structure example
This commit is contained in:
17
web/middleware.go
Normal file
17
web/middleware.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package web
|
||||
|
||||
import "net/http"
|
||||
|
||||
func WithAuth(f http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
// TODO check request auth
|
||||
f(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
func WithCompression(f http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
// TODO wrap writter in compressor
|
||||
f(w, r)
|
||||
}
|
||||
}
|
||||
33
web/server.go
Normal file
33
web/server.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func NewServer() *Server {
|
||||
server := &Server{
|
||||
Router: mux.NewRouter(),
|
||||
}
|
||||
server.HandleFunc("/todos", server.todos).Methods("GET")
|
||||
server.HandleFunc("/todos", WithAuth(server.todoCreate)).Methods("POST")
|
||||
server.HandleFunc("/todos", WithAuth(server.todoDelete)).Methods("DELETE")
|
||||
return server
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
*mux.Router
|
||||
}
|
||||
|
||||
func (server *Server) todos(w http.ResponseWriter, r *http.Request) {
|
||||
// TODO get
|
||||
}
|
||||
|
||||
func (server *Server) todoCreate(w http.ResponseWriter, r *http.Request) {
|
||||
// TODO get
|
||||
}
|
||||
|
||||
func (server *Server) todoDelete(w http.ResponseWriter, r *http.Request) {
|
||||
// TODO get
|
||||
}
|
||||
Reference in New Issue
Block a user