chore: archi package du projet

This commit is contained in:
Laurent Drogou
2021-04-13 14:09:58 +02:00
parent 7544643cfb
commit 8cdf1ca15f
9 changed files with 126 additions and 97 deletions

57
routeserv/server.go Normal file
View File

@@ -0,0 +1,57 @@
package routeserv
import (
"encoding/json"
"log"
"net/http"
"github.com/gorilla/mux"
"github.com/ldrogou/goauth20/middleware"
"github.com/ldrogou/goauth20/store"
)
type Server struct {
Router *mux.Router
Store store.Store
}
//File structure du fichier
type File struct {
JwtID int64
JwtProduce string
Header string
Payload string
Sign string
}
func NewServer() *Server {
s := &Server{
Router: mux.NewRouter(),
}
s.routes()
return s
}
func (s *Server) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
middleware.LogRequestMiddleware(s.Router.ServeHTTP).ServeHTTP(rw, r)
}
func (s *Server) response(rw http.ResponseWriter, _ *http.Request, data interface{}, status int) {
rw.Header().Add("Content-type", "application/json")
rw.WriteHeader(status)
if data == nil {
return
}
err := json.NewEncoder(rw).Encode(data)
if err != nil {
log.Printf("Cannot encode to json (err=%v)\n", err)
}
}
func (s *Server) decode(rw http.ResponseWriter, r *http.Request, v interface{}) error {
return json.NewDecoder(r.Body).Decode(v)
}