mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-12-04 18:19:54 +00:00
Migrate to gorilla/mux for web needs
What a wonderful package!
This commit is contained in:
parent
e7ddb54877
commit
6fdab4be34
@ -30,17 +30,17 @@ var (
|
|||||||
AllowRegistration bool
|
AllowRegistration bool
|
||||||
RegistrationLimit uint64
|
RegistrationLimit uint64
|
||||||
Locked bool
|
Locked bool
|
||||||
UseWhiteList bool
|
UseWhiteList bool
|
||||||
WhiteList []string
|
WhiteList []string
|
||||||
|
|
||||||
CommonScripts []string
|
CommonScripts []string
|
||||||
ViewScripts []string
|
ViewScripts []string
|
||||||
EditScripts []string
|
EditScripts []string
|
||||||
|
|
||||||
// TelegramEnabled if both TelegramBotToken and TelegramBotName are not empty strings.
|
// TelegramEnabled if both TelegramBotToken and TelegramBotName are not empty strings.
|
||||||
TelegramEnabled bool
|
TelegramEnabled bool
|
||||||
TelegramBotToken string
|
TelegramBotToken string
|
||||||
TelegramBotName string
|
TelegramBotName string
|
||||||
)
|
)
|
||||||
|
|
||||||
// WikiDir is a full path to the wiki storage directory, which also must be a
|
// WikiDir is a full path to the wiki storage directory, which also must be a
|
||||||
@ -56,7 +56,7 @@ type Config struct {
|
|||||||
Network
|
Network
|
||||||
Authorization
|
Authorization
|
||||||
CustomScripts `comment:"You can specify additional scripts to load on different kinds of pages, delimited by a comma ',' sign."`
|
CustomScripts `comment:"You can specify additional scripts to load on different kinds of pages, delimited by a comma ',' sign."`
|
||||||
Telegram `comment:"You can enable Telegram authorization. Follow these instructions: https://core.telegram.org/widgets/login#setting-up-a-bot"`
|
Telegram `comment:"You can enable Telegram authorization. Follow these instructions: https://core.telegram.org/widgets/login#setting-up-a-bot"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hyphae is a section of Config which has fields related to special hyphae.
|
// Hyphae is a section of Config which has fields related to special hyphae.
|
||||||
@ -89,16 +89,16 @@ type CustomScripts struct {
|
|||||||
type Authorization struct {
|
type Authorization struct {
|
||||||
UseAuth bool
|
UseAuth bool
|
||||||
AllowRegistration bool
|
AllowRegistration bool
|
||||||
RegistrationLimit uint64 `comment:"This field controls the maximum amount of allowed registrations."`
|
RegistrationLimit uint64 `comment:"This field controls the maximum amount of allowed registrations."`
|
||||||
Locked bool `comment:"Set if users have to authorize to see anything on the wiki."`
|
Locked bool `comment:"Set if users have to authorize to see anything on the wiki."`
|
||||||
UseWhiteList bool `comment:"If true, WhiteList is used. Else it is not used."`
|
UseWhiteList bool `comment:"If true, WhiteList is used. Else it is not used."`
|
||||||
WhiteList []string `delim:"," comment:"Usernames of people who can log in to your wiki separated by comma."`
|
WhiteList []string `delim:"," comment:"Usernames of people who can log in to your wiki separated by comma."`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Telegram is the section of Config that sets Telegram authorization.
|
// Telegram is the section of Config that sets Telegram authorization.
|
||||||
type Telegram struct {
|
type Telegram struct {
|
||||||
TelegramBotToken string `comment:"Token of your bot.`
|
TelegramBotToken string `comment:"Token of your bot.`
|
||||||
TelegramBotName string `comment:"Username of your bot, sans @.`
|
TelegramBotName string `comment:"Username of your bot, sans @.`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadConfigFile reads a config on the given path and stores the
|
// ReadConfigFile reads a config on the given path and stores the
|
||||||
@ -121,8 +121,8 @@ func ReadConfigFile(path string) error {
|
|||||||
AllowRegistration: false,
|
AllowRegistration: false,
|
||||||
RegistrationLimit: 0,
|
RegistrationLimit: 0,
|
||||||
Locked: false,
|
Locked: false,
|
||||||
UseWhiteList: false,
|
UseWhiteList: false,
|
||||||
WhiteList: []string{},
|
WhiteList: []string{},
|
||||||
},
|
},
|
||||||
CustomScripts: CustomScripts{
|
CustomScripts: CustomScripts{
|
||||||
CommonScripts: []string{},
|
CommonScripts: []string{},
|
||||||
@ -131,7 +131,7 @@ func ReadConfigFile(path string) error {
|
|||||||
},
|
},
|
||||||
Telegram: Telegram{
|
Telegram: Telegram{
|
||||||
TelegramBotToken: "",
|
TelegramBotToken: "",
|
||||||
TelegramBotName: "",
|
TelegramBotName: "",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
go.mod
1
go.mod
@ -6,6 +6,7 @@ require (
|
|||||||
github.com/bouncepaw/mycomarkup v0.5.8
|
github.com/bouncepaw/mycomarkup v0.5.8
|
||||||
github.com/go-ini/ini v1.62.0
|
github.com/go-ini/ini v1.62.0
|
||||||
github.com/gorilla/feeds v1.1.1
|
github.com/gorilla/feeds v1.1.1
|
||||||
|
github.com/gorilla/mux v1.8.0
|
||||||
github.com/kr/pretty v0.2.1 // indirect
|
github.com/kr/pretty v0.2.1 // indirect
|
||||||
github.com/smartystreets/goconvey v1.6.4 // indirect
|
github.com/smartystreets/goconvey v1.6.4 // indirect
|
||||||
github.com/valyala/quicktemplate v1.6.3
|
github.com/valyala/quicktemplate v1.6.3
|
||||||
|
2
go.sum
2
go.sum
@ -7,6 +7,8 @@ github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGa
|
|||||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||||
github.com/gorilla/feeds v1.1.1 h1:HwKXxqzcRNg9to+BbvJog4+f3s/xzvtZXICcQGutYfY=
|
github.com/gorilla/feeds v1.1.1 h1:HwKXxqzcRNg9to+BbvJog4+f3s/xzvtZXICcQGutYfY=
|
||||||
github.com/gorilla/feeds v1.1.1/go.mod h1:Nk0jZrvPFZX1OBe5NPiddPw7CfwF6Q9eqzaBbaightA=
|
github.com/gorilla/feeds v1.1.1/go.mod h1:Nk0jZrvPFZX1OBe5NPiddPw7CfwF6Q9eqzaBbaightA=
|
||||||
|
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
|
||||||
|
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
||||||
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
|
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
|
||||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||||
github.com/klauspost/compress v1.10.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
|
github.com/klauspost/compress v1.10.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
|
||||||
|
4
httpd.go
4
httpd.go
@ -11,12 +11,12 @@ import (
|
|||||||
"github.com/bouncepaw/mycorrhiza/cfg"
|
"github.com/bouncepaw/mycorrhiza/cfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
func serveHTTP() {
|
func serveHTTP(handler http.Handler) {
|
||||||
server := &http.Server{
|
server := &http.Server{
|
||||||
ReadTimeout: 300 * time.Second,
|
ReadTimeout: 300 * time.Second,
|
||||||
WriteTimeout: 300 * time.Second,
|
WriteTimeout: 300 * time.Second,
|
||||||
IdleTimeout: 300 * time.Second,
|
IdleTimeout: 300 * time.Second,
|
||||||
Handler: http.DefaultServeMux,
|
Handler: handler,
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(cfg.ListenAddr, "/") {
|
if strings.HasPrefix(cfg.ListenAddr, "/") {
|
||||||
|
4
main.go
4
main.go
@ -45,7 +45,5 @@ func main() {
|
|||||||
// Static files:
|
// Static files:
|
||||||
static.InitFS(files.StaticFiles())
|
static.InitFS(files.StaticFiles())
|
||||||
|
|
||||||
// Network:
|
serveHTTP(web.Handler())
|
||||||
web.Init()
|
|
||||||
serveHTTP()
|
|
||||||
}
|
}
|
||||||
|
10
user/net.go
10
user/net.go
@ -1,15 +1,15 @@
|
|||||||
package user
|
package user
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
"crypto/hmac"
|
"crypto/hmac"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/bouncepaw/mycorrhiza/cfg"
|
"github.com/bouncepaw/mycorrhiza/cfg"
|
||||||
"github.com/bouncepaw/mycorrhiza/util"
|
"github.com/bouncepaw/mycorrhiza/util"
|
||||||
@ -64,7 +64,7 @@ func Register(username, password, group, source string, force bool) error {
|
|||||||
u := User{
|
u := User{
|
||||||
Name: username,
|
Name: username,
|
||||||
Group: group,
|
Group: group,
|
||||||
Source: source,
|
Source: source,
|
||||||
Password: string(hash),
|
Password: string(hash),
|
||||||
RegisteredAt: time.Now(),
|
RegisteredAt: time.Now(),
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ type User struct {
|
|||||||
Password string `json:"hashed_password"`
|
Password string `json:"hashed_password"`
|
||||||
RegisteredAt time.Time `json:"registered_on"`
|
RegisteredAt time.Time `json:"registered_on"`
|
||||||
// Source is where the user from. Valid values: valid, telegram.
|
// Source is where the user from. Valid values: valid, telegram.
|
||||||
Source string `json:"source"`
|
Source string `json:"source"`
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
|
|
||||||
// A note about why HashedPassword is string and not []byte. The reason is
|
// A note about why HashedPassword is string and not []byte. The reason is
|
||||||
@ -77,7 +77,7 @@ func EmptyUser() *User {
|
|||||||
Name: "anon",
|
Name: "anon",
|
||||||
Group: "anon",
|
Group: "anon",
|
||||||
Password: "",
|
Password: "",
|
||||||
Source: "local",
|
Source: "local",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
14
web/admin.go
14
web/admin.go
@ -9,6 +9,8 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
|
|
||||||
"github.com/bouncepaw/mycorrhiza/cfg"
|
"github.com/bouncepaw/mycorrhiza/cfg"
|
||||||
"github.com/bouncepaw/mycorrhiza/user"
|
"github.com/bouncepaw/mycorrhiza/user"
|
||||||
"github.com/bouncepaw/mycorrhiza/util"
|
"github.com/bouncepaw/mycorrhiza/util"
|
||||||
@ -16,14 +18,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// initAdmin sets up /admin routes if auth is used. Call it after you have decided if you want to use auth.
|
// initAdmin sets up /admin routes if auth is used. Call it after you have decided if you want to use auth.
|
||||||
func initAdmin() {
|
func initAdmin(r *mux.Router) {
|
||||||
if cfg.UseAuth {
|
if cfg.UseAuth {
|
||||||
http.HandleFunc("/admin/", handlerAdmin)
|
r.HandleFunc("/admin/shutdown", handlerAdminShutdown)
|
||||||
http.HandleFunc("/admin/shutdown/", handlerAdminShutdown)
|
r.HandleFunc("/admin/reindex-users", handlerAdminReindexUsers)
|
||||||
http.HandleFunc("/admin/reindex-users/", handlerAdminReindexUsers)
|
|
||||||
|
|
||||||
http.HandleFunc("/admin/users/", handlerAdminUsers)
|
r.PathPrefix("/admin/users/").HandlerFunc(handlerAdminUsers)
|
||||||
http.HandleFunc("/admin/user/new", handlerAdminUserNew)
|
r.HandleFunc("/admin/user/new", handlerAdminUserNew)
|
||||||
|
r.HandleFunc("/admin", handlerAdmin)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
24
web/auth.go
24
web/auth.go
@ -9,27 +9,29 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
|
|
||||||
"github.com/bouncepaw/mycorrhiza/cfg"
|
"github.com/bouncepaw/mycorrhiza/cfg"
|
||||||
"github.com/bouncepaw/mycorrhiza/user"
|
"github.com/bouncepaw/mycorrhiza/user"
|
||||||
"github.com/bouncepaw/mycorrhiza/util"
|
"github.com/bouncepaw/mycorrhiza/util"
|
||||||
"github.com/bouncepaw/mycorrhiza/views"
|
"github.com/bouncepaw/mycorrhiza/views"
|
||||||
)
|
)
|
||||||
|
|
||||||
func initAuth() {
|
func initAuth(r *mux.Router) {
|
||||||
http.HandleFunc("/lock", handlerLock)
|
r.HandleFunc("/lock", handlerLock)
|
||||||
if !cfg.UseAuth {
|
if !cfg.UseAuth {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if cfg.AllowRegistration {
|
if cfg.AllowRegistration {
|
||||||
http.HandleFunc("/register", handlerRegister)
|
r.HandleFunc("/register", handlerRegister)
|
||||||
}
|
}
|
||||||
if cfg.TelegramEnabled {
|
if cfg.TelegramEnabled {
|
||||||
http.HandleFunc("/telegram-login", handlerTelegramLogin)
|
r.HandleFunc("/telegram-login", handlerTelegramLogin)
|
||||||
}
|
}
|
||||||
http.HandleFunc("/login", handlerLogin)
|
r.HandleFunc("/login", handlerLogin)
|
||||||
http.HandleFunc("/login-data", handlerLoginData)
|
r.HandleFunc("/login-data", handlerLoginData)
|
||||||
http.HandleFunc("/logout", handlerLogout)
|
r.HandleFunc("/logout", handlerLogout)
|
||||||
http.HandleFunc("/logout-confirm", handlerLogoutConfirm)
|
r.HandleFunc("/logout-confirm", handlerLogoutConfirm)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handlerLock(w http.ResponseWriter, rq *http.Request) {
|
func handlerLock(w http.ResponseWriter, rq *http.Request) {
|
||||||
@ -128,10 +130,10 @@ func handlerTelegramLogin(w http.ResponseWriter, rq *http.Request) {
|
|||||||
w.Header().Set("Content-Type", "text/html;charset=utf-8")
|
w.Header().Set("Content-Type", "text/html;charset=utf-8")
|
||||||
rq.ParseForm()
|
rq.ParseForm()
|
||||||
var (
|
var (
|
||||||
values = rq.URL.Query()
|
values = rq.URL.Query()
|
||||||
username = strings.ToLower(values.Get("username"))
|
username = strings.ToLower(values.Get("username"))
|
||||||
seemsValid = user.TelegramAuthParamsAreValid(values)
|
seemsValid = user.TelegramAuthParamsAreValid(values)
|
||||||
err = user.Register(
|
err = user.Register(
|
||||||
username,
|
username,
|
||||||
"", // Password matters not
|
"", // Password matters not
|
||||||
"editor",
|
"editor",
|
||||||
|
@ -7,18 +7,21 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
|
|
||||||
"github.com/bouncepaw/mycorrhiza/history"
|
"github.com/bouncepaw/mycorrhiza/history"
|
||||||
"github.com/bouncepaw/mycorrhiza/user"
|
"github.com/bouncepaw/mycorrhiza/user"
|
||||||
"github.com/bouncepaw/mycorrhiza/util"
|
"github.com/bouncepaw/mycorrhiza/util"
|
||||||
"github.com/bouncepaw/mycorrhiza/views"
|
"github.com/bouncepaw/mycorrhiza/views"
|
||||||
)
|
)
|
||||||
|
|
||||||
func initHistory() {
|
func initHistory(r *mux.Router) {
|
||||||
http.HandleFunc("/history/", handlerHistory)
|
r.PathPrefix("/history/").HandlerFunc(handlerHistory)
|
||||||
http.HandleFunc("/recent-changes/", handlerRecentChanges)
|
|
||||||
http.HandleFunc("/recent-changes-rss", handlerRecentChangesRSS)
|
r.PathPrefix("/recent-changes/").HandlerFunc(handlerRecentChanges)
|
||||||
http.HandleFunc("/recent-changes-atom", handlerRecentChangesAtom)
|
r.HandleFunc("/recent-changes-rss", handlerRecentChangesRSS)
|
||||||
http.HandleFunc("/recent-changes-json", handlerRecentChangesJSON)
|
r.HandleFunc("/recent-changes-atom", handlerRecentChangesAtom)
|
||||||
|
r.HandleFunc("/recent-changes-json", handlerRecentChangesJSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
// handlerHistory lists all revisions of a hypha.
|
// handlerHistory lists all revisions of a hypha.
|
||||||
|
@ -7,6 +7,8 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
|
|
||||||
"github.com/bouncepaw/mycorrhiza/history"
|
"github.com/bouncepaw/mycorrhiza/history"
|
||||||
"github.com/bouncepaw/mycorrhiza/hyphae"
|
"github.com/bouncepaw/mycorrhiza/hyphae"
|
||||||
"github.com/bouncepaw/mycorrhiza/shroom"
|
"github.com/bouncepaw/mycorrhiza/shroom"
|
||||||
@ -15,18 +17,18 @@ import (
|
|||||||
"github.com/bouncepaw/mycorrhiza/views"
|
"github.com/bouncepaw/mycorrhiza/views"
|
||||||
)
|
)
|
||||||
|
|
||||||
func initMutators() {
|
func initMutators(r *mux.Router) {
|
||||||
// Those that do not actually mutate anything:
|
// Those that do not actually mutate anything:
|
||||||
http.HandleFunc("/edit/", handlerEdit)
|
r.PathPrefix("/edit/").HandlerFunc(handlerEdit)
|
||||||
http.HandleFunc("/delete-ask/", handlerDeleteAsk)
|
r.PathPrefix("/delete-ask/").HandlerFunc(handlerDeleteAsk)
|
||||||
http.HandleFunc("/rename-ask/", handlerRenameAsk)
|
r.PathPrefix("/rename-ask/").HandlerFunc(handlerRenameAsk)
|
||||||
http.HandleFunc("/unattach-ask/", handlerUnattachAsk)
|
r.PathPrefix("/unattach-ask/").HandlerFunc(handlerUnattachAsk)
|
||||||
// And those that do mutate something:
|
// And those that do mutate something:
|
||||||
http.HandleFunc("/upload-binary/", handlerUploadBinary)
|
r.PathPrefix("/upload-binary/").HandlerFunc(handlerUploadBinary)
|
||||||
http.HandleFunc("/upload-text/", handlerUploadText)
|
r.PathPrefix("/upload-text/").HandlerFunc(handlerUploadText)
|
||||||
http.HandleFunc("/delete-confirm/", handlerDeleteConfirm)
|
r.PathPrefix("/delete-confirm/").HandlerFunc(handlerDeleteConfirm)
|
||||||
http.HandleFunc("/rename-confirm/", handlerRenameConfirm)
|
r.PathPrefix("/rename-confirm/").HandlerFunc(handlerRenameConfirm)
|
||||||
http.HandleFunc("/unattach-confirm/", handlerUnattachConfirm)
|
r.PathPrefix("/unattach-confirm/").HandlerFunc(handlerUnattachConfirm)
|
||||||
}
|
}
|
||||||
|
|
||||||
func factoryHandlerAsker(
|
func factoryHandlerAsker(
|
||||||
|
@ -2,14 +2,14 @@ package web
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/bouncepaw/mycomarkup/mycocontext"
|
|
||||||
"github.com/bouncepaw/mycorrhiza/cfg"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
|
|
||||||
"github.com/bouncepaw/mycorrhiza/history"
|
"github.com/bouncepaw/mycorrhiza/history"
|
||||||
"github.com/bouncepaw/mycorrhiza/hyphae"
|
"github.com/bouncepaw/mycorrhiza/hyphae"
|
||||||
"github.com/bouncepaw/mycorrhiza/mimetype"
|
"github.com/bouncepaw/mycorrhiza/mimetype"
|
||||||
@ -18,16 +18,18 @@ import (
|
|||||||
"github.com/bouncepaw/mycorrhiza/views"
|
"github.com/bouncepaw/mycorrhiza/views"
|
||||||
|
|
||||||
"github.com/bouncepaw/mycomarkup"
|
"github.com/bouncepaw/mycomarkup"
|
||||||
|
"github.com/bouncepaw/mycomarkup/mycocontext"
|
||||||
|
"github.com/bouncepaw/mycorrhiza/cfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
func initReaders() {
|
func initReaders(r *mux.Router) {
|
||||||
http.HandleFunc("/page/", handlerHypha)
|
r.PathPrefix("/page/").HandlerFunc(handlerHypha)
|
||||||
http.HandleFunc("/hypha/", handlerHypha)
|
r.PathPrefix("/hypha/").HandlerFunc(handlerHypha)
|
||||||
http.HandleFunc("/text/", handlerText)
|
r.PathPrefix("/text/").HandlerFunc(handlerText)
|
||||||
http.HandleFunc("/binary/", handlerBinary)
|
r.PathPrefix("/binary/").HandlerFunc(handlerBinary)
|
||||||
http.HandleFunc("/rev/", handlerRevision)
|
r.PathPrefix("/rev/").HandlerFunc(handlerRevision)
|
||||||
http.HandleFunc("/primitive-diff/", handlerPrimitiveDiff)
|
r.PathPrefix("/primitive-diff/").HandlerFunc(handlerPrimitiveDiff)
|
||||||
http.HandleFunc("/attachment/", handlerAttachment)
|
r.PathPrefix("/attachment/").HandlerFunc(handlerAttachment)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handlerAttachment(w http.ResponseWriter, rq *http.Request) {
|
func handlerAttachment(w http.ResponseWriter, rq *http.Request) {
|
||||||
|
@ -1,19 +1,20 @@
|
|||||||
package web
|
package web
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/bouncepaw/mycorrhiza/shroom"
|
|
||||||
"github.com/bouncepaw/mycorrhiza/user"
|
|
||||||
"github.com/bouncepaw/mycorrhiza/views"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
|
|
||||||
|
"github.com/bouncepaw/mycorrhiza/shroom"
|
||||||
|
"github.com/bouncepaw/mycorrhiza/user"
|
||||||
"github.com/bouncepaw/mycorrhiza/util"
|
"github.com/bouncepaw/mycorrhiza/util"
|
||||||
|
"github.com/bouncepaw/mycorrhiza/views"
|
||||||
)
|
)
|
||||||
|
|
||||||
func initSearch() {
|
func initSearch(r *mux.Router) {
|
||||||
http.HandleFunc("/title-search/", handlerTitleSearch)
|
r.PathPrefix("/title-search/").HandlerFunc(handlerTitleSearch)
|
||||||
http.HandleFunc("/title-search-json/", handlerTitleSearchJSON) // we get a little shroomy
|
r.PathPrefix("/title-search-json/").HandlerFunc(handlerTitleSearchJSON)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func handlerTitleSearch(w http.ResponseWriter, rq *http.Request) {
|
func handlerTitleSearch(w http.ResponseWriter, rq *http.Request) {
|
||||||
|
26
web/stuff.go
26
web/stuff.go
@ -2,33 +2,35 @@ package web
|
|||||||
|
|
||||||
// stuff.go is used for meta stuff about the wiki or all hyphae at once.
|
// stuff.go is used for meta stuff about the wiki or all hyphae at once.
|
||||||
import (
|
import (
|
||||||
"github.com/bouncepaw/mycomarkup"
|
|
||||||
"github.com/bouncepaw/mycomarkup/mycocontext"
|
|
||||||
"github.com/bouncepaw/mycorrhiza/help"
|
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
|
|
||||||
"github.com/bouncepaw/mycorrhiza/cfg"
|
"github.com/bouncepaw/mycorrhiza/cfg"
|
||||||
"github.com/bouncepaw/mycorrhiza/files"
|
"github.com/bouncepaw/mycorrhiza/files"
|
||||||
|
"github.com/bouncepaw/mycorrhiza/help"
|
||||||
"github.com/bouncepaw/mycorrhiza/hyphae"
|
"github.com/bouncepaw/mycorrhiza/hyphae"
|
||||||
"github.com/bouncepaw/mycorrhiza/shroom"
|
"github.com/bouncepaw/mycorrhiza/shroom"
|
||||||
"github.com/bouncepaw/mycorrhiza/user"
|
"github.com/bouncepaw/mycorrhiza/user"
|
||||||
"github.com/bouncepaw/mycorrhiza/util"
|
"github.com/bouncepaw/mycorrhiza/util"
|
||||||
"github.com/bouncepaw/mycorrhiza/views"
|
"github.com/bouncepaw/mycorrhiza/views"
|
||||||
|
|
||||||
|
"github.com/bouncepaw/mycomarkup"
|
||||||
|
"github.com/bouncepaw/mycomarkup/mycocontext"
|
||||||
)
|
)
|
||||||
|
|
||||||
func initStuff() {
|
func initStuff(r *mux.Router) {
|
||||||
http.HandleFunc("/help/", handlerHelp)
|
r.PathPrefix("/help/").HandlerFunc(handlerHelp)
|
||||||
http.HandleFunc("/list/", handlerList)
|
r.HandleFunc("/list", handlerList)
|
||||||
http.HandleFunc("/reindex/", handlerReindex)
|
r.HandleFunc("/reindex", handlerReindex)
|
||||||
http.HandleFunc("/update-header-links/", handlerUpdateHeaderLinks)
|
r.HandleFunc("/update-header-links", handlerUpdateHeaderLinks)
|
||||||
http.HandleFunc("/random/", handlerRandom)
|
r.HandleFunc("/random", handlerRandom)
|
||||||
http.HandleFunc("/about/", handlerAbout)
|
r.HandleFunc("/about", handlerAbout)
|
||||||
http.HandleFunc("/favicon.ico", func(w http.ResponseWriter, rq *http.Request) {
|
r.HandleFunc("/favicon.ico", func(w http.ResponseWriter, rq *http.Request) {
|
||||||
http.Redirect(w, rq, "/static/favicon.ico", http.StatusSeeOther)
|
http.Redirect(w, rq, "/static/favicon.ico", http.StatusSeeOther)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
50
web/web.go
50
web/web.go
@ -11,6 +11,8 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
|
|
||||||
"github.com/bouncepaw/mycorrhiza/cfg"
|
"github.com/bouncepaw/mycorrhiza/cfg"
|
||||||
"github.com/bouncepaw/mycorrhiza/static"
|
"github.com/bouncepaw/mycorrhiza/static"
|
||||||
"github.com/bouncepaw/mycorrhiza/user"
|
"github.com/bouncepaw/mycorrhiza/user"
|
||||||
@ -73,27 +75,43 @@ func handlerRobotsTxt(w http.ResponseWriter, rq *http.Request) {
|
|||||||
file.Close()
|
file.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func Init() {
|
func Handler() http.Handler {
|
||||||
initAdmin()
|
r := mux.NewRouter()
|
||||||
initReaders()
|
r.Use(func(next http.Handler) http.Handler {
|
||||||
initMutators()
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
initAuth()
|
// Do stuff here
|
||||||
initHistory()
|
log.Println(r.RequestURI)
|
||||||
initStuff()
|
// Call the next handler, which can be another middleware in the chain, or the final handler.
|
||||||
initSearch()
|
next.ServeHTTP(w, r)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// Available all the time
|
||||||
|
initAuth(r)
|
||||||
|
|
||||||
|
initReaders(r)
|
||||||
|
initMutators(r)
|
||||||
|
|
||||||
|
initAdmin(r)
|
||||||
|
initHistory(r)
|
||||||
|
initStuff(r)
|
||||||
|
initSearch(r)
|
||||||
|
|
||||||
// Miscellaneous
|
// Miscellaneous
|
||||||
http.HandleFunc("/user-list/", handlerUserList)
|
r.HandleFunc("/user-list", handlerUserList)
|
||||||
http.HandleFunc("/robots.txt", handlerRobotsTxt)
|
r.HandleFunc("/robots.txt", handlerRobotsTxt)
|
||||||
|
|
||||||
// Static assets
|
// Static assets
|
||||||
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.FS(static.FS))))
|
r.HandleFunc("/static/style.css", handlerStyle)
|
||||||
http.HandleFunc("/static/style.css", handlerStyle)
|
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.FS(static.FS))))
|
||||||
|
|
||||||
// Index page
|
// Index page
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, rq *http.Request) {
|
r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
addr, _ := url.Parse("/hypha/" + cfg.HomeHypha) // Let's pray it never fails
|
// Let's pray it never fails
|
||||||
rq.URL = addr
|
addr, _ := url.Parse("/hypha/" + cfg.HomeHypha)
|
||||||
handlerHypha(w, rq)
|
r.URL = addr
|
||||||
|
handlerHypha(w, r)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return r
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user