goHttpEcho

package
v0.3.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2024 License: GPL-3.0 Imports: 19 Imported by: 4

Documentation

Index

Constants

View Source
const (
	MIMEAppJSON            = "application/json"
	MIMEHtml               = "text/html"
	MIMEAppJSONCharsetUTF8 = MIMEAppJSON + "; " + charsetUTF8
	HeaderContentType      = "Content-Type"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AppInfo added in v0.3.2

type AppInfo struct {
	App        string `json:"app"`
	Version    string `json:"version"`
	Repository string `json:"repository"`
}

type Authentication added in v0.3.2

type Authentication interface {
	AuthenticateUser(user, passwordHash string) bool
	GetUserInfoFromLogin(login string) (*UserInfo, error)
}

func NewSimpleAdminAuthenticator added in v0.3.2

func NewSimpleAdminAuthenticator(u *UserInfo, mainAdminPassword string, jwtCheck JwtChecker) Authentication

NewSimpleAdminAuthenticator Function to create an instance of SimpleAdminAuthenticator

type Config added in v0.3.2

type Config struct {
	ListenAddress string
	Authenticator Authentication
	JwtCheck      JwtChecker
	VersionReader VersionReader
	Logger        golog.MyLogger
	WebRootDir    string
	Content       embed.FS
	RestrictedUrl string
}

type FuncAreWeHealthy

type FuncAreWeHealthy func(msg string) bool

type FuncAreWeReady

type FuncAreWeReady func(msg string) bool

type JwtChecker added in v0.3.2

type JwtChecker interface {
	ParseToken(jwtToken string) (*JwtCustomClaims, error)
	GetTokenFromUserInfo(userInfo *UserInfo) (*jwt.Token, error)
	JwtMiddleware(next echo.HandlerFunc) echo.HandlerFunc
	GetLogger() golog.MyLogger
	GetJwtDuration() int
	GetIssuerId() string
	GetJwtCustomClaimsFromContext(c echo.Context) *JwtCustomClaims
}

func NewJwtChecker added in v0.3.2

func NewJwtChecker(secret, issuer, subject, contextKey string, duration int, l golog.MyLogger) JwtChecker

NewJwtChecker creates a new JwtChecker

type JwtCustomClaims

type JwtCustomClaims struct {
	jwt.RegisteredClaims
	User *UserInfo
}

JwtCustomClaims are custom claims extending default ones.

type JwtInfo added in v0.3.2

type JwtInfo struct {
	Secret        string `json:"secret"`
	Duration      int    `json:"duration"`
	IssuerId      string `json:"issuer_id"`
	Subject       string `json:"subject"`
	JwtContextKey string `json:"jwt_context_key"` // Context key for storing the JWT token
	// contains filtered or unexported fields
}

func (*JwtInfo) GetIssuerId added in v0.3.2

func (ji *JwtInfo) GetIssuerId() string

func (*JwtInfo) GetJwtCustomClaimsFromContext added in v0.3.2

func (ji *JwtInfo) GetJwtCustomClaimsFromContext(c echo.Context) *JwtCustomClaims

GetJwtCustomClaimsFromContext returns the JWT Custom claims from the Echo context

func (*JwtInfo) GetJwtDuration added in v0.3.2

func (ji *JwtInfo) GetJwtDuration() int

func (*JwtInfo) GetLogger added in v0.3.2

func (ji *JwtInfo) GetLogger() golog.MyLogger

func (*JwtInfo) GetTokenFromUserInfo added in v0.3.2

func (ji *JwtInfo) GetTokenFromUserInfo(userInfo *UserInfo) (*jwt.Token, error)

func (*JwtInfo) JwtMiddleware added in v0.3.2

func (ji *JwtInfo) JwtMiddleware(next echo.HandlerFunc) echo.HandlerFunc

func (*JwtInfo) ParseToken added in v0.3.2

func (ji *JwtInfo) ParseToken(jwtToken string) (*JwtCustomClaims, error)

type Server added in v0.3.2

type Server struct {
	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.2

func CreateNewServerFromEnvOrFail(defaultPort int, defaultServerIp string, srvConfig *Config) *Server

CreateNewServerFromEnvOrFail creates a new server from environment variables or fails

func NewGoHttpServer

func NewGoHttpServer(serverConfig *Config) *Server

NewGoHttpServer is a constructor that initializes the server,routes and all fields in Server type

func (*Server) AddGetRoute added in v0.3.2

func (s *Server) AddGetRoute(baseURL string, urlPath string, handler echo.HandlerFunc)

AddGetRoute adds a handler for this web server

func (*Server) GetEcho added in v0.3.2

func (s *Server) GetEcho() *echo.Echo

GetEcho returns a pointer to the Echo reference

func (*Server) GetHealthHandler added in v0.3.2

func (s *Server) GetHealthHandler(healthyFunc FuncAreWeHealthy, msg string) echo.HandlerFunc

func (*Server) GetListenAddress added in v0.3.2

func (s *Server) GetListenAddress() string

GetListenAddress returns the listen address of this web server

func (*Server) GetLog added in v0.3.2

func (s *Server) GetLog() golog.MyLogger

GetLog returns the log of this web server

func (*Server) GetReadinessHandler added in v0.3.2

func (s *Server) GetReadinessHandler(readyFunc FuncAreWeReady, msg string) echo.HandlerFunc

func (*Server) GetRestrictedGroup added in v0.3.2

func (s *Server) GetRestrictedGroup() *echo.Group

GetRestrictedGroup adds a handler for this web server

func (*Server) GetRouter added in v0.3.2

func (s *Server) GetRouter() *http.ServeMux

GetRouter returns the ServeMux of this web server

func (*Server) GetStartTime added in v0.3.2

func (s *Server) GetStartTime() time.Time

GetStartTime returns the start time of this web server

func (*Server) StartServer added in v0.3.2

func (s *Server) StartServer() error

StartServer initializes all the handlers paths of this web server, it is called inside the NewGoHttpServer constructor

type SimpleAdminAuthenticator added in v0.3.2

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.2

func (sa *SimpleAdminAuthenticator) AuthenticateUser(userLogin, passwordHash string) bool

AuthenticateUser Implement the AuthenticateUser method for SimpleAdminAuthenticator

func (*SimpleAdminAuthenticator) GetUserInfoFromLogin added in v0.3.2

func (sa *SimpleAdminAuthenticator) GetUserInfoFromLogin(login string) (*UserInfo, error)

GetUserInfoFromLogin Get the JWT claims from the login User

type SimpleVersionWriter added in v0.3.2

type SimpleVersionWriter struct {
	Version AppInfo
}

SimpleVersionWriter Create a struct that will implement the VersionReader interface

func NewSimpleVersionReader added in v0.3.2

func NewSimpleVersionReader(app, ver, repo string) *SimpleVersionWriter

NewSimpleVersionReader is a constructor that initializes the VersionReader interface

func (SimpleVersionWriter) GetVersionInfo added in v0.3.2

func (s SimpleVersionWriter) GetVersionInfo() AppInfo

GetVersionInfo returns the version information of the application.

type UserInfo added in v0.3.2

type UserInfo struct {
	UserId     int    `json:"user_id"`
	ExternalId int    `json:"external_id"`
	Name       string `json:"name"`
	Email      string `json:"email"`
	Login      string `json:"login"`
	IsAdmin    bool   `json:"is_admin"`
	Groups     []int  `json:"groups"`
}

UserInfo are custom claims extending default ones.

type VersionReader added in v0.3.2

type VersionReader interface {
	GetVersionInfo() AppInfo
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL