Documentation ¶
Index ¶
- Constants
- func GetHandlerNotFound(l golog.MyLogger, rootPathNotFoundCounter prometheus.Counter) http.HandlerFunc
- func GetHealthHandler(l golog.MyLogger) http.HandlerFunc
- func GetInfoHandler(s *Server) http.HandlerFunc
- func GetLoginPostHandler(s *Server) http.HandlerFunc
- func GetReadinessHandler(l golog.MyLogger) http.HandlerFunc
- func GetStaticPageHandler(title string, description string, l golog.MyLogger) http.HandlerFunc
- func GetTimeHandler(l golog.MyLogger) http.HandlerFunc
- func TraceRequest(handlerName string, r *http.Request, l golog.MyLogger)
- func WaitForHttpServer(listenAddress string, waitDuration time.Duration, numRetries int)
- type AppInfo
- type Authentication
- type JwtChecker
- type JwtCustomClaims
- type JwtInfo
- func (ji *JwtInfo) GetIssuerId() string
- func (ji *JwtInfo) GetJwtDuration() int
- func (ji *JwtInfo) GetLogger() golog.MyLogger
- func (ji *JwtInfo) GetTokenFromUserInfo(userInfo *UserInfo) (*jwt.Token, error)
- func (ji *JwtInfo) JwtMiddleware(next http.Handler) http.Handler
- func (ji *JwtInfo) ParseToken(jwtToken string) (*JwtCustomClaims, error)
- type PrometheusMiddleware
- type Server
- func (s *Server) AddRoute(pathPattern string, handler http.Handler)
- func (s *Server) GetLog() golog.MyLogger
- func (s *Server) GetPrometheusRegistry() *prometheus.Registry
- func (s *Server) GetRouter() *http.ServeMux
- func (s *Server) GetStartTime() time.Time
- func (s *Server) JsonResponse(w http.ResponseWriter, result interface{}) error
- func (s *Server) StartServer()
- type SimpleAdminAuthenticator
- type SimpleVersionWriter
- type UserInfo
- type VersionReader
Constants ¶
const ( MIMEAppJSON = "application/json" MIMEHtml = "text/html" MIMEAppJSONCharsetUTF8 = MIMEAppJSON + "; " + charsetUTF8 HeaderContentType = "Content-Type" )
Variables ¶
This section is empty.
Functions ¶
func GetHandlerNotFound ¶
func GetHandlerNotFound(l golog.MyLogger, rootPathNotFoundCounter prometheus.Counter) http.HandlerFunc
func GetHealthHandler ¶
func GetHealthHandler(l golog.MyLogger) http.HandlerFunc
func GetInfoHandler ¶ added in v0.3.1
func GetInfoHandler(s *Server) http.HandlerFunc
func GetLoginPostHandler ¶ added in v0.3.1
func GetLoginPostHandler(s *Server) http.HandlerFunc
func GetReadinessHandler ¶
func GetReadinessHandler(l golog.MyLogger) http.HandlerFunc
func GetStaticPageHandler ¶ added in v0.3.1
func GetTimeHandler ¶
func GetTimeHandler(l golog.MyLogger) http.HandlerFunc
Types ¶
type Authentication ¶ added in v0.3.1
type Authentication interface { AuthenticateUser(user, passwordHash string) bool GetUserInfoFromLogin(login string) (*UserInfo, error) }
func NewSimpleAdminAuthenticator ¶ added in v0.3.1
func NewSimpleAdminAuthenticator(mainAdminUser, mainAdminPassword, mainAdminEmail string, mainAdminId int, jwtCheck JwtChecker) Authentication
NewSimpleAdminAuthenticator Function to create an instance of SimpleAdminAuthenticator
type JwtChecker ¶ added in v0.3.1
type JwtChecker interface { ParseToken(jwtToken string) (*JwtCustomClaims, error) GetTokenFromUserInfo(userInfo *UserInfo) (*jwt.Token, error) JwtMiddleware(next http.Handler) http.Handler GetLogger() golog.MyLogger GetJwtDuration() int GetIssuerId() string }
func NewJwtChecker ¶ added in v0.3.1
func NewJwtChecker(secret, issuer, subject string, duration int, l golog.MyLogger) JwtChecker
NewJwtChecker creates a new JwtChecker
type JwtCustomClaims ¶ added in v0.3.1
type JwtCustomClaims struct { jwt.RegisteredClaims User *UserInfo }
JwtCustomClaims are custom claims extending default ones.
func GetJwtCustomClaimsFromContext ¶ added in v0.3.1
func GetJwtCustomClaimsFromContext(r *http.Request) *JwtCustomClaims
GetJwtCustomClaimsFromContext returns the JWT Custom claims from the received request with context
type JwtInfo ¶ added in v0.3.1
type JwtInfo struct { Secret string `json:"secret"` Duration int `json:"duration"` IssuerId string `json:"issuer_id"` Subject string `json:"subject"` // contains filtered or unexported fields }
func (*JwtInfo) GetIssuerId ¶ added in v0.3.1
func (*JwtInfo) GetJwtDuration ¶ added in v0.3.1
func (*JwtInfo) GetTokenFromUserInfo ¶ added in v0.3.1
func (*JwtInfo) JwtMiddleware ¶ added in v0.3.1
func (*JwtInfo) ParseToken ¶ added in v0.3.1
func (ji *JwtInfo) ParseToken(jwtToken string) (*JwtCustomClaims, error)
type PrometheusMiddleware ¶ added in v0.3.1
type PrometheusMiddleware interface { // WrapHandler wraps the given HTTP handler WrapHandler(handlerName string, handler http.Handler) http.HandlerFunc }
func NewPrometheusMiddleware ¶ added in v0.3.1
func NewPrometheusMiddleware(registry prometheus.Registerer, buckets []float64) PrometheusMiddleware
NewPrometheusMiddleware returns a PrometheusMiddleware interface.
type Server ¶
type Server struct { RootPathGetCounter prometheus.Counter PathNotFoundCounter prometheus.Counter Authenticator Authentication JwtCheck JwtChecker VersionReader VersionReader // contains filtered or unexported fields }
Server is a struct type to store information related to all handlers of web server
func CreateNewServerFromEnvOrFail ¶ added in v0.3.1
func CreateNewServerFromEnvOrFail( defaultPort int, defaultServerIp string, myAuthenticator Authentication, myJwt JwtChecker, myVersionReader VersionReader, l golog.MyLogger, ) *Server
CreateNewServerFromEnvOrFail creates a new server from environment variables or fails
func NewGoHttpServer ¶
func NewGoHttpServer(listenAddress string, Auth Authentication, JwtCheck JwtChecker, Ver VersionReader, logger golog.MyLogger) *Server
NewGoHttpServer is a constructor that initializes the server mux (routes) and all fields of the Server type
func (*Server) GetPrometheusRegistry ¶ added in v0.3.1
func (s *Server) GetPrometheusRegistry() *prometheus.Registry
GetPrometheusRegistry returns the Prometheus registry of this web server
func (*Server) GetStartTime ¶
GetStartTime returns the start time of this web server
func (*Server) JsonResponse ¶
func (s *Server) JsonResponse(w http.ResponseWriter, result interface{}) error
func (*Server) StartServer ¶
func (s *Server) StartServer()
StartServer initializes all the handlers paths of this web server, it is called inside the NewGoHttpServer constructor
type SimpleAdminAuthenticator ¶ added in v0.3.1
type SimpleAdminAuthenticator struct {
// contains filtered or unexported fields
}
SimpleAdminAuthenticator Create a struct that will implement the Authentication interface
func (*SimpleAdminAuthenticator) AuthenticateUser ¶ added in v0.3.1
func (sa *SimpleAdminAuthenticator) AuthenticateUser(userLogin, passwordHash string) bool
AuthenticateUser Implement the AuthenticateUser method for SimpleAdminAuthenticator
func (*SimpleAdminAuthenticator) GetUserInfoFromLogin ¶ added in v0.3.1
func (sa *SimpleAdminAuthenticator) GetUserInfoFromLogin(login string) (*UserInfo, error)
GetUserInfoFromLogin Get the JWT claims from the login User
type SimpleVersionWriter ¶ added in v0.3.1
type SimpleVersionWriter struct {
Version AppInfo
}
SimpleVersionWriter Create a struct that will implement the VersionReader interface
func NewSimpleVersionReader ¶ added in v0.3.1
func NewSimpleVersionReader(app, ver, repo, build string) *SimpleVersionWriter
NewSimpleVersionReader is a constructor that initializes the VersionReader interface
func (SimpleVersionWriter) GetVersionInfo ¶ added in v0.3.1
func (s SimpleVersionWriter) GetVersionInfo() AppInfo
GetVersionInfo returns the version information of the application.
type UserInfo ¶ added in v0.3.1
type UserInfo struct { UserId int `json:"user_id"` UserName string `json:"user_name"` UserEmail string `json:"user_email"` UserLogin string `json:"user_login"` IsAdmin bool `json:"is_admin"` }
UserInfo are custom claims extending default ones.
type VersionReader ¶ added in v0.3.1
type VersionReader interface {
GetVersionInfo() AppInfo
}