wrap

package
v0.0.0-...-b015d54 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: GPL-3.0 Imports: 32 Imported by: 1

Documentation

Overview

#### Packages

  • github.com/spf13/viper
  • github.com/stretchr/testify
  • github.com/hashicorp/consul/api
  • google.golang.org/grpc
  • github.com/gin-gonic/gin
  • gopkg.in/gomail.v2
  • github.com/golang-jwt/jwt/v4
  • go.uber.org/multierr
  • go.uber.org/zap
  • gopkg.in/natefinch/lumberjack.v2

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheControl

func CacheControl(seconds int) gin.HandlerFunc

func ConfigFromBytes

func ConfigFromBytes(bts []byte, typ string) (conf *viper.Viper, err error)

func ConsulConfigDemo

func ConsulConfigDemo() string

func Cors

func Cors(origin string) gin.HandlerFunc

func CtxValue

func CtxValue[T any](ctx *gin.Context, key string) (v T, ok bool)

func DemoJwtHSAuth

func DemoJwtHSAuth(auth *JwtHSAuth, handle func(*gin.Context, map[string]any) error,
) gin.HandlerFunc

func GetAddr

func GetAddr(ctx *gin.Context) (ap netip.AddrPort, err error)

func GetAddrString

func GetAddrString(ctx *gin.Context) string

func Healthz

func Healthz(ctx *gin.Context)

func LogLevelFromStr

func LogLevelFromStr(level string) zapcore.Level

func OpenConfig

func OpenConfig(fp string, types ...string) (conf *viper.Viper, err error)

func Pprof

func Pprof(rg *gin.RouterGroup, handlers ...gin.HandlerFunc)

func ReadStringField

func ReadStringField(fp, sp string) (out string, err error)

func RootStaticFiles

func RootStaticFiles(router *gin.RouterGroup, d string) (err error)

func UnmarshalConfig

func UnmarshalConfig(fp string, objects map[string]any) (err error)

func WriteJSON

func WriteJSON(ctx *gin.Context, code int, bts []byte) (int, error)

code: http.StatusOK...

func WsUpgrade

func WsUpgrade(ctx *gin.Context)

Types

type ConsulClient

type ConsulClient struct {
	Address  string `mapstructure:"address" json:"address"`              // consul address
	SecretId string `mapstructure:"secret_id" json:"secretId,omitempty"` // consul secretId

	Name     string   `mapstructure:"name" json:"name,omitempty"`         // name of service
	Registry bool     `mapstructure:"registry" json:"registry,omitempty"` // enable registry or not
	Tags     []string `mapstructure:"tags" json:"tags,omitempty"`         // service tags
	Timeout  string   `mapstructure:"timeout" json:"timeout,omitempty"`   // api.AgentServiceCheck.Timeout
	Interval string   `mapstructure:"interval" json:"interval,omitempty"` // api.AgentServiceCheck.Interval
	DCSA     string   `mapstructure:"dcsa" json:"dcsa,omitempty"`         // api.AgentServiceCheck.DeregisterCriticalServiceAfter

	*api.Client `mapstructure:"-"`
	// contains filtered or unexported fields
}

Configuration:

```yaml consul:

address: http://127.0.0.1:8500
secret_id: xxxxyyyy

# service_id could be empty string
name: "my-service"
tags: ["A", "B", "C"]
registry: true
# default values
timeout: "5s"
interval: "5s"
dcsa: "15s" # deregister_critical_service_after

```

func NewConsulClient

func NewConsulClient(fp, field string) (cc *ConsulClient, err error)

fp: consul yaml config file

func (*ConsulClient) Deregister

func (cc *ConsulClient) Deregister() (err error)

func (*ConsulClient) GRPCRegister

func (cc *ConsulClient) GRPCRegister(port int, useTLS bool, srv *grpc.Server) (err error)

func (*ConsulClient) GetHealthServices

func (cc *ConsulClient) GetHealthServices(name string, q *api.QueryOptions) (
	services []*api.AgentService, err error)

func (*ConsulClient) GetKV

func (cc *ConsulClient) GetKV(key string) (vc *viper.Viper, err error)

func (*ConsulClient) GetServices

func (cc *ConsulClient) GetServices(name string) (services []*api.AgentService, err error)

func (*ConsulClient) HTTPRegister

func (cc *ConsulClient) HTTPRegister(port int, useTLS bool, p string) (err error)

p: http health path, port: service port

func (*ConsulClient) SetServiceId

func (cc *ConsulClient) SetServiceId(id string)

type Email

type Email struct {
	Recipients []string `mapstructure:"recipients"`
	Title      string   `mapstructure:"title"`
	Body       string   `mapstructure:"body"`
	Attachs    []string `mapstructure:"attachs"`
}

type JwtHSAuth

type JwtHSAuth struct {
	// contains filtered or unexported fields
}

func NewHSAuth

func NewHSAuth(key string, code uint) (auth *JwtHSAuth, err error)

func (*JwtHSAuth) Parse

func (auth *JwtHSAuth) Parse(str string) (data map[string]any, err error)

func (*JwtHSAuth) Sign

func (auth *JwtHSAuth) Sign(data map[string]any) (str string, err error)

type JwtRSAAuth

type JwtRSAAuth struct {
	// contains filtered or unexported fields
}

func NewRSAAuth

func NewRSAAuth(privateKeyFile, publicKeyFile string, code uint) (auth *JwtRSAAuth, err error)

func (*JwtRSAAuth) Parse

func (auth *JwtRSAAuth) Parse(str string) (data map[string]any, err error)

func (*JwtRSAAuth) Sign

func (auth *JwtRSAAuth) Sign(data map[string]any) (str string, err error)

type Logger

type Logger struct {
	Writer *lumberjack.Logger

	*zap.Logger
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger(filename string, level zapcore.LevelEnabler, mbs int, w io.Writer,
	skips ...int) (logger *Logger)

func (*Logger) Down

func (logger *Logger) Down() (err error)

type Sender

type Sender struct {
	SMTPAddr string `mapstructure:"smtp_addr"`
	SMTPPort int    `mapstructure:"smtp_port"`
	Address  string `mapstructure:"address"`
	Password string `mapstructure:"password"`
}

func NewSender

func NewSender(fp, field string) (sender *Sender, err error)

func (*Sender) Send

func (sender *Sender) Send(email *Email) (err error)

type StaticDir

type StaticDir func(*gin.RouterGroup) error

func ServeStatic

func ServeStatic(dir, local string, listDir bool) StaticDir

Jump to

Keyboard shortcuts

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