util

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultAddr              = ":1409"
	DefaultWriteTimeout      = Duration(1000 * time.Millisecond)
	DefaultReadTimeout       = Duration(1000 * time.Millisecond)
	DefaultReadHeaderTimeout = Duration(1000 * time.Millisecond)
	DefaultIdleTimeout       = Duration(1000 * time.Millisecond)
	DefaultCloseTimeout      = Duration(5 * time.Second)
	DefaultMonitorInterval   = Duration(10 * time.Second)
)

Variables

This section is empty.

Functions

func Bytes2String

func Bytes2String(b []byte) string

func HTTPResponse added in v0.0.3

func HTTPResponse(success bool, message string, data interface{}, httpCode int, w http.ResponseWriter) error

func NewPool added in v0.0.3

func NewPool() *sync.Pool

func String2Bytes

func String2Bytes(s string) []byte

Types

type DB

type DB struct {
	*gorm.DB
	UserName string
	Password string
	IP       string
	Port     int
	DBName   string
	Charset  string

	Logger *zap.Logger
}

func NewDB

func NewDB(UserName string, Password string, IP string, Port int, DBName string, Charset string) (*DB, error)

func (*DB) Close

func (db *DB) Close() error

func (*DB) Open

func (db *DB) Open() error

type Duration

type Duration time.Duration

func (Duration) ToDuration

func (d Duration) ToDuration() time.Duration

func (Duration) UnmarshalYAML

func (d Duration) UnmarshalYAML(unmarshal func(v interface{}) error) error

type HTTPd added in v0.0.3

type HTTPd struct {
	Config HTTPdConfig

	Closing chan struct{}
	Closed  chan struct{}

	Logger *zap.Logger

	Validator *validator.Validate
	// contains filtered or unexported fields
}

func NewHTTPd added in v0.0.3

func NewHTTPd(config HTTPdConfig) (*HTTPd, error)

func (*HTTPd) Close added in v0.0.3

func (s *HTTPd) Close() error

func (*HTTPd) Open added in v0.0.3

func (s *HTTPd) Open() error

func (*HTTPd) ReadBodyFail added in v0.0.3

func (s *HTTPd) ReadBodyFail(w http.ResponseWriter, err error)

func (*HTTPd) Response added in v0.0.3

func (s *HTTPd) Response(success bool, message string, data interface{}, httpCode int, w http.ResponseWriter)

func (*HTTPd) Serve added in v0.0.3

func (s *HTTPd) Serve()

func (*HTTPd) SetHandler added in v0.0.3

func (s *HTTPd) SetHandler(router *mux.Router)

func (*HTTPd) UnmarshalFail added in v0.0.3

func (s *HTTPd) UnmarshalFail(w http.ResponseWriter, err error)

func (*HTTPd) ValidateFail added in v0.0.3

func (s *HTTPd) ValidateFail(w http.ResponseWriter, err error)

func (*HTTPd) WithLogger added in v0.0.3

func (s *HTTPd) WithLogger(logger *zap.Logger)

type HTTPdConfig added in v0.0.3

type HTTPdConfig struct {
	Addr              string   `yaml:"Addr,omitempty" mapstructure:"Addr,omitempty"`
	WriteTimeout      Duration `yaml:"WriteTimeout,omitempty" mapstructure:"WriteTimeout,omitempty"`
	ReadTimeout       Duration `yaml:"ReadTimeout,omitempty" mapstructure:"ReadTimeout,omitempty"`
	ReadHeaderTimeout Duration `yaml:"ReadHeaderTimeout,omitempty" mapstructure:"ReadHeaderTimeout,omitempty"`
	IdleTimeout       Duration `yaml:"IdleTimeout,omitempty" mapstructure:"IdleTimeout,omitempty"`
	CloseTimeout      Duration `yaml:"CloseTimeout,omitempty" mapstructure:"CloseTimeout,omitempty"`
	MonitorInterval   Duration `yaml:"MonitorInterval,omitempty" mapstructure:"MonitorInterval,omitempty"`
}

func NewHTTPdConfig added in v0.0.3

func NewHTTPdConfig() HTTPdConfig

type HttpResponse added in v0.0.3

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

func GetResponseWrapper added in v0.0.3

func GetResponseWrapper() *HttpResponse

func GetResponseWrapperFromBytes added in v0.0.3

func GetResponseWrapperFromBytes(bs []byte) (*HttpResponse, error)

func GetResponseWrapperFromString added in v0.0.3

func GetResponseWrapperFromString(s string) (*HttpResponse, error)

func (*HttpResponse) Free added in v0.0.3

func (hr *HttpResponse) Free()

func (*HttpResponse) GetData added in v0.0.3

func (hr *HttpResponse) GetData() interface{}

func (*HttpResponse) GetMessage added in v0.0.3

func (hr *HttpResponse) GetMessage() string

func (*HttpResponse) GetResponse added in v0.0.3

func (hr *HttpResponse) GetResponse() *response

func (*HttpResponse) GetSuccess added in v0.0.3

func (hr *HttpResponse) GetSuccess() bool

func (*HttpResponse) SetData added in v0.0.3

func (hr *HttpResponse) SetData(d interface{})

func (*HttpResponse) SetMessage added in v0.0.3

func (hr *HttpResponse) SetMessage(m string)

func (*HttpResponse) SetSuccess added in v0.0.3

func (hr *HttpResponse) SetSuccess(s bool)

Jump to

Keyboard shortcuts

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