hlog

package
v0.0.0-...-e8daaa7 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abbreviate

func Abbreviate(str string, maxWidth int) string

Abbreviate abbreviates a string using ellipses.

func AnyPrefix

func AnyPrefix(s string, prefixes ...string) bool

func At

func At(s []string, i int) string

At returns the element of index i in the slice s.

func GetRemoteAddress

func GetRemoteAddress(r *http.Request) string

GetRemoteAddress returns ip address of the client making the request, taking into account http proxies.

func IPAddrFromRemoteAddr

func IPAddrFromRemoteAddr(s string) string

IPAddrFromRemoteAddr parses the IP Address. Request.RemoteAddress contains port, which we want to remove i.e.: "[::1]:58292" => "[::1]".

func If

func If(b bool, s1, s2 string) string

func IsWsRequest

func IsWsRequest(url string) bool

IsWsRequest return true if this request is a websocket request.

func PeekBody

func PeekBody(r *http.Request, maxSize int) []byte

PeekBody peeks the maxSize body from the request limit to maxSize bytes.

func PutAttr

func PutAttr(c *gin.Context, key string, value interface{})

PutAttr put an attribute into the Attributes in the context.

func PutAttrMap

func PutAttrMap(c *gin.Context, attrs map[string]interface{})

PutAttrMap put an attribute map into the Attributes in the context.

Types

type Adapter

type Adapter struct {
	Store Store
}

func NewAdapter

func NewAdapter(store Store) *Adapter

func (*Adapter) Adapt

func (a *Adapter) Adapt(relativePath string, argV interface{}) adapt.Handler

func (*Adapter) Biz

func (a *Adapter) Biz(biz string) OptionFn

func (*Adapter) Default

func (a *Adapter) Default(relativePath string) adapt.Handler

func (*Adapter) F

func (a *Adapter) F(fns ...OptionFn) adapt.Parent

func (*Adapter) Ignore

func (a *Adapter) Ignore() OptionFn

func (*Adapter) MaxSize

func (a *Adapter) MaxSize(v int) OptionFn

func (*Adapter) Tables

func (a *Adapter) Tables(tables ...string) OptionFn

type Attrs

type Attrs map[string]interface{}

Attrs carries map. It implements value for that key and delegates all other calls to the embedded Context.

type Log

type Log struct {
	ID  string
	Biz string

	// Method is GET etc.
	Method string
	URL    string
	IPAddr string

	RspHeader http.Header
	ReqBody   string

	// RspStatus, like 200, 404.
	RspStatus int
	// ReqHeader records the response header.
	ReqHeader http.Header
	// RespSize is number of bytes of the response sent.
	RespSize int
	// RspBody is the response body(limit to 1000).
	RspBody string

	Created time.Time

	// Start records the start time of the request.
	Start time.Time
	// End records the end time of the request.
	End time.Time
	// Duration means how long did it take to.
	Duration time.Duration
	Attrs    Attrs

	Option     *Option
	PathParams gin.Params
	Request    *http.Request
}

Log describes info about HTTP request.

type LogrusStore

type LogrusStore struct{}

LogrusStore stores the log as logurs info.

func NewLogrusStore

func NewLogrusStore() *LogrusStore

NewLogrusStore returns a new LogrusStore.

func (*LogrusStore) Store

func (s *LogrusStore) Store(c *gin.Context, log *Log)

Store stores the log in database like MySQL, InfluxDB, and etc.

type Middle

type Middle struct {
	P *Adapter
	// contains filtered or unexported fields
}

func (*Middle) Before

func (m *Middle) Before(c *gin.Context) (after adapt.Handler)

func (*Middle) Handle

func (m *Middle) Handle(c *gin.Context)

type Option

type Option struct {
	MaxSize int
	Biz     string
	Ignore  bool
	Tables  []string
}

func NewOption

func NewOption() *Option

type OptionFn

type OptionFn func(option *Option)

type SQLStore

type SQLStore struct {
	DB        sqx.SqxDB
	LogTables []string

	TableCols map[string]*tableSchema
}

SQLStore stores the log into database.

func NewSQLStore

func NewSQLStore(db sqx.SqxDB, defaultLogTables ...string) *SQLStore

NewSQLStore creates a new SQLStore.

func (*SQLStore) Store

func (s *SQLStore) Store(c *gin.Context, l *Log)

Store stores the log in database like MySQL, InfluxDB, and etc.

type Store

type Store interface {
	// Store stores the log in database like MySQL, InfluxDB, and etc.
	Store(c *gin.Context, log *Log)
}

Store defines the interface to Store a log.

type Stores

type Stores struct {
	Composite []Store
}

Stores is the composite stores.

func NewStores

func NewStores(stores ...Store) *Stores

NewStores composes the stores as a Store.

func (*Stores) Store

func (s *Stores) Store(c *gin.Context, log *Log)

Store stores the log in database like MySQL, InfluxDB, and etc.

type TableCol

type TableCol struct {
	Name      string `name:"column_name"`
	Comment   string `name:"column_comment"`
	DataType  string `name:"data_type"`
	Extra     string `name:"extra"`
	Nullable  string `name:"nullable"`
	MaxLength int    `name:"max_length"`

	ValueGetter col `name:"-"`
}

TableCol defines the schema of a table.

func (*TableCol) IsNullable

func (s *TableCol) IsNullable() bool

Jump to

Keyboard shortcuts

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