contact

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2020 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Config = ConfigMap{
	App: struct {
		Port int
		Mode string
	}{
		Port: 8000,
		Mode: "release",
	},
	OpenTracing: struct {
		Service string
		Sampler struct {
			Type  string
			Param float64
		}
		Reporter struct {
			LogSpans           bool
			LocalAgentHostPort string
		}
	}{
		Service: "App",
		Sampler: struct {
			Type  string
			Param float64
		}{
			Type:  "const",
			Param: 1,
		}, Reporter: struct {
			LogSpans           bool
			LocalAgentHostPort string
		}{
			LogSpans:           false,
			LocalAgentHostPort: "localhost:6831",
		},
	},
}
View Source
var ConfigPath = "./config.yml"
View Source
var CorsConfig = Cors{
	AllowOrigin:      []string{"*"},
	AllowHeaders:     []string{"Content-Type", "AccessToken", "X-CSRF-Token", "Authorization", "X-Requested-With"},
	AllowMethods:     []string{"POST", "GET", "OPTIONS", "PUT", "PATCH", "DELETE"},
	AllowCredentials: false,
}
View Source
var GinPage = page{PageKey: "page", PageSizeKey: "page_size", PageSizeDefault: 15, CurrentDefault: 1}
View Source
var LogPath = "logs"
View Source
var RedisClient *redis.Client
View Source
var ServerErrorWrite = new(ServerErrorIO)

Functions

func CURD added in v0.0.17

func CURD(r *gin.Engine, prefix string, model Model) *gin.RouterGroup

ref: https://developer.github.com/v3/#http-verbs

func ClientSpanWrap added in v0.0.8

func ClientSpanWrap(tracer opentracing.Tracer, span opentracing.Span) *resty.Client

func Close added in v0.0.11

func Close()

func ConfigFile added in v0.0.8

func ConfigFile(path string, dst interface{}) bool

func GinCors added in v0.0.5

func GinCors() gin.HandlerFunc

func GinHelpHandle

func GinHelpHandle(h GinHelpHandlerFunc) gin.HandlerFunc

func GinOpenTracing added in v0.0.8

func GinOpenTracing() gin.HandlerFunc

func GinPageBase added in v0.0.18

func GinPageBase(cb GinDataEnginePageHelp, current int, size int) interface{}

func GinRouteAuth added in v0.0.4

func GinRouteAuth() gin.HandlerFunc

func Init added in v0.0.11

func Init()

func InitConfig

func InitConfig()

func InitDB

func InitDB(mode string) *sql.DB

func InitFlag added in v0.0.5

func InitFlag()

func InitGin

func InitGin()

func InitLog added in v0.0.4

func InitLog()

func InitOpenTracing added in v0.0.8

func InitOpenTracing() (opentracing.Tracer, io.Closer)

func InitRedis added in v0.0.4

func InitRedis()

func IsForgetToken added in v0.0.4

func IsForgetToken(token string) (int64, bool)

func LogClose added in v0.0.4

func LogClose() error

func RedisClose added in v0.0.4

func RedisClose() error

func SpanWrap added in v0.0.8

func SpanWrap(tracer opentracing.Tracer, key string, span opentracing.Span) opentracing.Span

Types

type Body added in v0.0.17

type Body struct {
	Payload interface{}
}

type BoolField

type BoolField struct {
	Bool bool
}

func (BoolField) MarshalJSON added in v0.0.3

func (b BoolField) MarshalJSON() ([]byte, error)

func (*BoolField) Scan

func (b *BoolField) Scan(value interface{}) error

func (BoolField) UnmarshalJSON added in v0.0.3

func (b BoolField) UnmarshalJSON(data []byte) (err error)

func (BoolField) Value

func (b BoolField) Value() (driver.Value, error)

type Claim

type Claim struct {
	jwt.StandardClaims
}

type ConfigMap

type ConfigMap struct {
	Database map[string]map[string]interface{}

	Jwt struct {
		Secret string
	}

	App struct {
		Port int
		Mode string
	}

	Redis struct {
		Host     string
		Port     int
		Db       int
		Password string
	}

	OpenTracing struct {
		Service string
		Sampler struct {
			Type  string
			Param float64
		}
		Reporter struct {
			LogSpans           bool
			LocalAgentHostPort string
		}
	}
}

type Cors added in v0.0.6

type Cors struct {
	AllowOrigin  []string
	AllowHeaders []string
	AllowMethods []string
	// response header without Cache-Control、Content-Language、Content-Type、Expires、Last-Modified、Pragma
	// if client will get...
	ExposeHeaders    []string
	AllowCredentials bool
}

type GinDataEnginePageHelp added in v0.0.18

type GinDataEnginePageHelp func(current int, size int) interface{}

type GinHelp

type GinHelp struct {
	*gin.Context
	AppContext context.Context
}

func (*GinHelp) AssetsInValid added in v0.0.6

func (help *GinHelp) AssetsInValid(code string, err error)

断言客户端错误

func (*GinHelp) BadRequest

func (help *GinHelp) BadRequest(msg string)

客户端错误请求 不推荐使用 太过于底层 推荐InValid*

func (*GinHelp) ClientSpanWrapWithApp added in v0.0.8

func (help *GinHelp) ClientSpanWrapWithApp() *resty.Client

func (*GinHelp) Forbidden

func (help *GinHelp) Forbidden(msg string)

客户端权限不足 不推荐使用 太过于底层 推荐InValid*

func (*GinHelp) GetPageInfo added in v0.0.17

func (help *GinHelp) GetPageInfo() pageInfo

func (*GinHelp) GetToken added in v0.0.4

func (help *GinHelp) GetToken() string

获取token

func (*GinHelp) GinPageHelp added in v0.0.18

func (help *GinHelp) GinPageHelp(cb GinDataEnginePageHelp) interface{}

func (*GinHelp) GinPageHelpWithOptionSize added in v0.0.18

func (help *GinHelp) GinPageHelpWithOptionSize(cb GinDataEnginePageHelp, size int) interface{}

func (*GinHelp) InValid

func (help *GinHelp) InValid(code string, msg string)

客户端错误响应

func (*GinHelp) InValidBind

func (help *GinHelp) InValidBind(json interface{})

客户端body错误响应

func (*GinHelp) InValidBindQuery

func (help *GinHelp) InValidBindQuery(query interface{})

客户端query错误响应

func (*GinHelp) InValidBindUri added in v0.0.4

func (help *GinHelp) InValidBindUri(query interface{})

客户端uri错误响应

func (*GinHelp) InValidError added in v0.0.6

func (help *GinHelp) InValidError(code string, err error)

客户端错误响应

func (*GinHelp) Resource

func (help *GinHelp) Resource(data interface{})

成功响应

func (*GinHelp) ResourceCreate

func (help *GinHelp) ResourceCreate(data interface{})

创建成功响应

func (*GinHelp) ResourceDelete

func (help *GinHelp) ResourceDelete()

删除成功响应

func (*GinHelp) ResourceNotFound

func (help *GinHelp) ResourceNotFound()

资源丢失响应 不推荐使用 太过于底层 推荐InValid*

func (*GinHelp) ResourcePage added in v0.0.5

func (help *GinHelp) ResourcePage(data interface{}, total int)

分页响应辅助

func (*GinHelp) Response

func (help *GinHelp) Response(code int, jsonObj interface{})

响应

func (*GinHelp) ServerError

func (help *GinHelp) ServerError(msg string)

服务端错误响应 不推荐使用 太过于底层 推荐InValid*

func (*GinHelp) SpanWrapWithApp added in v0.0.8

func (help *GinHelp) SpanWrapWithApp(key string) opentracing.Span

func (*GinHelp) TracingSpan added in v0.0.8

func (help *GinHelp) TracingSpan() opentracing.Span

func (*GinHelp) TracingTracer added in v0.0.12

func (help *GinHelp) TracingTracer() opentracing.Tracer

func (*GinHelp) Unauthorized

func (help *GinHelp) Unauthorized(msg string)

客户端未认证 不推荐使用 太过于底层 推荐InValid*

type GinHelpHandlerFunc

type GinHelpHandlerFunc func(c *GinHelp)

type GinInValidFunc added in v0.0.12

type GinInValidFunc func(code string, message string) interface{}
var InValidFunc GinInValidFunc = defaultInValidFunc

type H

type H map[string]interface{}

type JsonArrayField added in v0.0.3

type JsonArrayField struct {
	Interface []interface{}
}

func (JsonArrayField) MarshalJSON added in v0.0.3

func (j JsonArrayField) MarshalJSON() ([]byte, error)

func (*JsonArrayField) Scan added in v0.0.3

func (j *JsonArrayField) Scan(value interface{}) (err error)

func (JsonArrayField) UnmarshalJSON added in v0.0.3

func (j JsonArrayField) UnmarshalJSON(data []byte) (err error)

func (JsonArrayField) Value added in v0.0.3

func (j JsonArrayField) Value() (driver.Value, error)

type JsonField

type JsonField struct {
	Interface map[string]interface{}
}

func (JsonField) MarshalJSON added in v0.0.3

func (j JsonField) MarshalJSON() ([]byte, error)

func (*JsonField) Scan

func (j *JsonField) Scan(value interface{}) (err error)

func (JsonField) UnmarshalJSON added in v0.0.3

func (j JsonField) UnmarshalJSON(data []byte) (err error)

func (JsonField) Value

func (j JsonField) Value() (driver.Value, error)

type JwtLib

type JwtLib struct {
	Claim
	Secret []byte
}

func JwtNew

func JwtNew() *JwtLib

func (*JwtLib) ForgetToken added in v0.0.4

func (j *JwtLib) ForgetToken()

func (*JwtLib) GenerateToken

func (j *JwtLib) GenerateToken() (token string)

func (*JwtLib) ParseToken

func (j *JwtLib) ParseToken(token string) (err error)

func (*JwtLib) RefreshToken

func (j *JwtLib) RefreshToken(addTime time.Duration) (token string)

func (*JwtLib) SetExpiresAt

func (j *JwtLib) SetExpiresAt(value int64) *JwtLib

func (*JwtLib) SetExpiresAt2Hour added in v0.0.4

func (j *JwtLib) SetExpiresAt2Hour(value int64) *JwtLib

func (*JwtLib) SetExpiresAtDay added in v0.0.4

func (j *JwtLib) SetExpiresAtDay(value int64) *JwtLib

func (*JwtLib) SetExpiresAtWeek added in v0.0.4

func (j *JwtLib) SetExpiresAtWeek() *JwtLib

func (*JwtLib) SetPrimaryKey

func (j *JwtLib) SetPrimaryKey(value string) *JwtLib

func (*JwtLib) SetSecret

func (j *JwtLib) SetSecret(secret string) *JwtLib

func (*JwtLib) SetSubInfo

func (j *JwtLib) SetSubInfo(value string) *JwtLib

type Model added in v0.0.17

type Model interface {
	List(interface{}) (interface{}, int, error)
	Get(string) (interface{}, error)
	Patch(string, interface{}) error
	Fill(create bool) interface{}
	Create(interface{}) (interface{}, error)
	Delete(string) error
	PrimaryKey() string
	SetContext(ctx context.Context)
}

type ResponseAbortError added in v0.0.4

type ResponseAbortError struct{}

func (ResponseAbortError) Error added in v0.0.6

func (r ResponseAbortError) Error() string

type ServerErrorIO added in v0.0.4

type ServerErrorIO struct{}

func (ServerErrorIO) Write added in v0.0.4

func (sew ServerErrorIO) Write(p []byte) (n int, err error)

type Trans

type Trans struct {
	Tran ut.Translator
}
var Tranintance Trans

Jump to

Keyboard shortcuts

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