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 ¶
- func CacheControl(seconds int) gin.HandlerFunc
- func ConfigFromBytes(bts []byte, typ string) (conf *viper.Viper, err error)
- func ConsulConfigDemo() string
- func Cors(origin string) gin.HandlerFunc
- func CtxValue[T any](ctx *gin.Context, key string) (v T, ok bool)
- func DemoJwtHSAuth(auth *JwtHSAuth, handle func(*gin.Context, map[string]any) error) gin.HandlerFunc
- func GetAddr(ctx *gin.Context) (ap netip.AddrPort, err error)
- func GetAddrString(ctx *gin.Context) string
- func Healthz(ctx *gin.Context)
- func LogLevelFromStr(level string) zapcore.Level
- func OpenConfig(fp string, types ...string) (conf *viper.Viper, err error)
- func Pprof(rg *gin.RouterGroup, handlers ...gin.HandlerFunc)
- func ReadStringField(fp, sp string) (out string, err error)
- func RootStaticFiles(router *gin.RouterGroup, d string) (err error)
- func ServeFavicon(bts []byte, ts ...time.Time) gin.HandlerFunc
- func UnmarshalConfig(fp string, objects map[string]any) (err error)
- func WriteJSON(ctx *gin.Context, code int, bts []byte) (int, error)
- func WsUpgrade(ctx *gin.Context)
- type ConsulClient
- func (cc *ConsulClient) Deregister() (err error)
- func (cc *ConsulClient) GRPCRegister(port int, useTLS bool, srv *grpc.Server) (err error)
- func (cc *ConsulClient) GetHealthServices(name string, q *api.QueryOptions) (services []*api.AgentService, err error)
- func (cc *ConsulClient) GetKV(key string) (vc *viper.Viper, err error)
- func (cc *ConsulClient) GetServices(name string) (services []*api.AgentService, err error)
- func (cc *ConsulClient) HTTPRegister(port int, useTLS bool, p string) (err error)
- func (cc *ConsulClient) SetServiceId(id string)
- type Email
- type JwtHSAuth
- type JwtRSAAuth
- type Logger
- type Sender
- type StaticDir
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CacheControl ¶
func CacheControl(seconds int) gin.HandlerFunc
func ConsulConfigDemo ¶
func ConsulConfigDemo() string
func Cors ¶
func Cors(origin string) gin.HandlerFunc
func DemoJwtHSAuth ¶
func GetAddrString ¶
func LogLevelFromStr ¶
func Pprof ¶
func Pprof(rg *gin.RouterGroup, handlers ...gin.HandlerFunc)
func ReadStringField ¶
func RootStaticFiles ¶
func RootStaticFiles(router *gin.RouterGroup, d string) (err error)
func ServeFavicon ¶
func ServeFavicon(bts []byte, ts ...time.Time) gin.HandlerFunc
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 (*ConsulClient) GetHealthServices ¶
func (cc *ConsulClient) GetHealthServices(name string, q *api.QueryOptions) ( services []*api.AgentService, 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 JwtRSAAuth ¶
type JwtRSAAuth struct {
// contains filtered or unexported fields
}
func NewRSAAuth ¶
func NewRSAAuth(privateKeyFile, publicKeyFile string, code uint) (auth *JwtRSAAuth, err error)
type Logger ¶
type Logger struct { Writer *lumberjack.Logger *zap.Logger // contains filtered or unexported fields }
type Sender ¶
Click to show internal directories.
Click to hide internal directories.