server

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2023 License: MIT Imports: 25 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Limiter = NewThrottle()

Functions

func CreateSSLCert added in v0.1.0

func CreateSSLCert(filename string, content string) string

CreateSSLCert makes cert in image

func GetServerCertificate added in v0.0.22

func GetServerCertificate() (string, string)

GetServerCertificate returns private and public key

func GetServerPKI added in v0.0.29

func GetServerPKI() (*rsa.PrivateKey, *rsa.PublicKey)

GetServerPKI returns public key infrustructure

func Use

func Use(h http.Handler, m ...Middleware) http.Handler

Use middleware

Types

type JWT

type JWT interface {
	CreateToken(tokenInfo TokenInfo) (string, error)
	IsValidToken(r *http.Request) bool
	GetTokenInfo(r *http.Request) (*TokenInfo, error)
	Secret() string
}

JWT

func NewJWT added in v0.1.0

func NewJWT(secret string, minutes int64, authorized bool) JWT

NewJWT

type Middleware

type Middleware func(http.Handler) http.Handler

Middleware strct

func IsAllowedIPs added in v0.1.5

func IsAllowedIPs(allowedIps string) Middleware

IsAllowedIPs allow specific IP address

func IsAllowedOrigin added in v0.1.5

func IsAllowedOrigin(allowedOrigin string) Middleware

IsAllowedOrigin enable cors within the http handler

func IsAuthenticated added in v0.1.5

func IsAuthenticated(jwt JWT) Middleware

IsAuthenticated validates request for jwt header

func IsAuthorized added in v0.1.5

func IsAuthorized(jwt JWT) Middleware

IsAuthorized validate if users is allowed to access route

func IsThrottle added in v0.1.5

func IsThrottle() Middleware

IsThrottle handle limits and rates

func NoAuthentication added in v0.1.5

func NoAuthentication() Middleware

NoAuthentication access without authentications

func Preflight

func Preflight() Middleware

Preflight validates request for jwt header

func ProcessTimeout added in v0.1.0

func ProcessTimeout(timeout time.Duration) Middleware

ProcessTimeout put a time limit for the handler process duration and will give an error response if timeout

func SetHeaders

func SetHeaders() Middleware

SetHeaders // prepare header response

type Params added in v0.0.12

type Params struct {
	ID     string      `json:"id,omitempty"`
	Params interface{} `json:"params,omitempty"`
	Cipher string      `json:"cipher,omitempty"`
}

Params

type Response

type Response struct {
	Result string `json:"result,omitempty"`
	Cipher string `json:"cipher,omitempty"`
}

Response result

type Server added in v0.1.0

type Server struct {
	Name     string
	Env      string
	URI      string
	Mux      *http.ServeMux
	Cache    *cache.Cache
	Database database.Database
	JWT      JWT
	Logger   *logrus.Logger

	ServerPublicKey *rsa.PublicKey

	Timeout uint64
	// contains filtered or unexported fields
}

Server struct

func NewServer added in v0.1.0

func NewServer(serviceName, URI string) *Server

NewServer get new instance of server

func (*Server) Error added in v0.1.0

func (s *Server) Error(w http.ResponseWriter, r *http.Request, err error)

Error returns error as json

func (*Server) Request added in v0.1.0

func (s *Server) Request(w http.ResponseWriter, r *http.Request) (interface{}, error)

request returns payload

func (*Server) Start added in v0.1.0

func (s *Server) Start()

Start the server

func (*Server) Success added in v0.1.0

func (s *Server) Success(w http.ResponseWriter, r *http.Request, data interface{})

Success returns object as json

type Throttle added in v0.1.0

type Throttle interface {
	IsThrottled(ip string) bool
}

func NewThrottle added in v0.1.0

func NewThrottle() Throttle

NewThrottle .

type TokenInfo added in v0.1.0

type TokenInfo struct {
	Permissions []string
	Origin      string
	ActorID     int64
}

TokenInfo struct

Jump to

Keyboard shortcuts

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