Add existing codebase
This commit is contained in:
commit
c23a68347b
16 changed files with 807 additions and 0 deletions
34
server.go
Normal file
34
server.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package link
|
||||
|
||||
import (
|
||||
"github.com/jackc/pgx/v4/pgxpool"
|
||||
"github.com/knadh/koanf"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v4/middleware"
|
||||
"link/link"
|
||||
)
|
||||
|
||||
func NewServer(conf *koanf.Koanf, pool *pgxpool.Pool) *echo.Echo {
|
||||
server := echo.New()
|
||||
|
||||
addMiddleware(server, conf)
|
||||
addHandlers(server, pool)
|
||||
|
||||
return server
|
||||
}
|
||||
|
||||
func addMiddleware(s *echo.Echo, conf *koanf.Koanf) {
|
||||
s.Use(middleware.CORS())
|
||||
|
||||
s.Use(middleware.JWTWithConfig(middleware.JWTConfig{
|
||||
Skipper: func(ctx echo.Context) bool {
|
||||
return ctx.Request().Method == "GET"
|
||||
},
|
||||
SigningMethod: conf.String("jwt.method"),
|
||||
SigningKey: conf.Bytes("jwt.key"),
|
||||
}))
|
||||
}
|
||||
|
||||
func addHandlers(s *echo.Echo, pool *pgxpool.Pool) {
|
||||
link.AddHandlers(s, pool)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue