first working version
This commit is contained in:
parent
14e0611f06
commit
85f93bae69
32 changed files with 863 additions and 571 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"github.com/gorilla/mux"
|
||||
"html/template"
|
||||
|
|
@ -9,6 +10,7 @@ import (
|
|||
"time"
|
||||
|
||||
"git.giftfish.de/ston1th/gowiki/pkg/db"
|
||||
"git.giftfish.de/ston1th/gowiki/pkg/log"
|
||||
"git.giftfish.de/ston1th/jwt"
|
||||
)
|
||||
|
||||
|
|
@ -17,9 +19,10 @@ const (
|
|||
)
|
||||
|
||||
type HTTPServer struct {
|
||||
Version string
|
||||
listener net.Listener
|
||||
srv *http.Server
|
||||
Version string
|
||||
indexPath string
|
||||
listener net.Listener
|
||||
srv *http.Server
|
||||
|
||||
DB *db.DB
|
||||
JWT *jwt.JWT
|
||||
|
|
@ -28,14 +31,11 @@ type HTTPServer struct {
|
|||
res map[string][]byte
|
||||
}
|
||||
|
||||
func NewHTTPServer(l net.Listener, versin string, secCookie bool) (srv *HTTPServer) {
|
||||
func NewHTTPServer(l net.Listener, version, indexPath string, secCookie bool) (srv *HTTPServer) {
|
||||
srv = &HTTPServer{
|
||||
Version: version,
|
||||
SecCookie: secCookie,
|
||||
listener: l,
|
||||
JWT: jwt.New(time.Hour*12, nil, nil),
|
||||
Version: version,
|
||||
listener: l,
|
||||
}
|
||||
srv.cookieStore()
|
||||
srv.loadTemplates()
|
||||
srv.srv = &http.Server{
|
||||
Handler: srv.buildRoutes(),
|
||||
|
|
@ -44,11 +44,13 @@ func NewHTTPServer(l net.Listener, versin string, secCookie bool) (srv *HTTPServ
|
|||
}
|
||||
|
||||
func (s *HTTPServer) Start() (err error) {
|
||||
s.DB, err = db.New()
|
||||
//TODO make secret configurable
|
||||
buf := bytes.NewBufferString("be688838ca8686e5c90689bf2ab585cef1137c999b48c70b92f67a5c34dc15697b5d11c982ed6d71be1e1e7f7b4e0733884aa97c3f7a339a8ed03577cf74be09")
|
||||
s.JWT, err = jwt.New(jwt.DefaultExpiry, jwt.NewMemBlacklist(), buf)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
s.Index, err = NewIndex(blevePath)
|
||||
s.DB, err = db.New(s.indexPath)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
@ -59,8 +61,8 @@ func (s *HTTPServer) Start() (err error) {
|
|||
}
|
||||
|
||||
func (s *HTTPServer) Stop() error {
|
||||
s.BS.Close()
|
||||
s.Index.Close()
|
||||
s.DB.Close()
|
||||
s.JWT.Stop()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||
defer cancel()
|
||||
return s.srv.Shutdown(ctx)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue