Documentation ¶
Index ¶
- Constants
- Variables
- func AddMetaDataTags(ws *restful.WebService, tags []string)
- func AddMetaDataTagsAndWriteSample(ws *restful.WebService, tags []string, entityType interface{})
- func AddWriteSample(ws *restful.WebService, entityType interface{})
- func CloseAllDB() error
- func Copy(toValue interface{}, fromValu interface{})
- func DB() (*gorm.DB, error)
- func DBs() ([]*gorm.DB, error)
- func EnvIsProd() bool
- func ExecSQLFile(fileName string) error
- func Migrate(assetNames []string, afn bindata.AssetFunc, dbURL, dialect string) error
- func NewAPIError(code int, msg, desc string) *apierrors.APIError
- func PageQueryParamters(req *restful.Request) (pageIndex, pageSize uint)
- func RedisClient() *redis.Client
- func Serve(svc []*restful.WebService)
- func Validate() *validator.Validate
- func ValidateEntity(entity interface{}) error
- func ValidateEntityAndWriteResp(res *restful.Response, entity interface{}, apiErr *apierrors.APIError) error
- func ValidateTranslator() ut.Translator
- type BaseController
- type BaseDO
- type BaseDTO
- type BaseResource
- type ComplexBaseDO
- type EmptyRespEntity
- type Entity
- type JSONDate
- type JSONTime
- type MultiDBSource
- type Page
- type PageDTO
- type Pageable
- type Pagination
- type RespEntity
- type Response
- type ResponseEntitySample
- type SampleBaseDO
- type Sort
Constants ¶
const ( //EnvPgTestDataFile import test data sql file EnvPgTestDataFile = "PG_TEST_DATA_FILE" //AppRunEnvLocal app run env "local" AppRunEnvLocal = "local" //AppRunEnvTest app run env "test" AppRunEnvTest = "test" //AppRunEnvProd app run env "prod" AppRunEnvProd = "prod" )
const ( //SortDirectionDESC 降序 SortDirectionDESC = "DESC" //SortDirectionASC 升序 SortDirectionASC = "ASC" )
const ( //PageIndexKey pagination page index default 0 PageIndexKey = "page_index" //DefaultPageIndexValue pagination page index default 0 DefaultPageIndexValue = 0 //PageSizeKey pagination page size default 10 PageSizeKey = "page_size" //DefaultPageSizeValue pagination page size default 10 DefaultPageSizeValue = 10 )
const KeyOpenAPITags = restfulspec.KeyOpenAPITags
KeyOpenAPITags is a Metadata key for a restful Route
Variables ¶
var ErrIDInvalid = NewAPIError(100001, "非法ID", "ID为数值且不能为0")
ErrIDInvalid REST resource ID invalid
var (
ErrNoDatabaseConfiguration = errors.New("there isn't any database setting in the configuration file")
)
var ErrPageParamsInvalid = NewAPIError(100002, "分页参数有误", "page_index,page_size为数值类型,page_size 大于5小于100 被5整除")
ErrPageParamsInvalid Pagination params invalid
Functions ¶
func AddMetaDataTags ¶ added in v0.3.7
func AddMetaDataTags(ws *restful.WebService, tags []string)
AddMetaDataTags add metadata tags to Webservice all routes
func AddMetaDataTagsAndWriteSample ¶ added in v0.3.8
func AddMetaDataTagsAndWriteSample(ws *restful.WebService, tags []string, entityType interface{})
AddMetaDataTagsAndWriteSample AddMetaDataTags() and WriteSample
func AddWriteSample ¶ added in v0.3.8
func AddWriteSample(ws *restful.WebService, entityType interface{})
AddWriteSample setting a webservice all routes to write sample with ResponseEntity
func Copy ¶ added in v0.2.0
func Copy(toValue interface{}, fromValu interface{})
Copy copy anyting. just proxy to copier(jinzhu/copier).
func EnvIsProd ¶ added in v0.4.3
func EnvIsProd() bool
EnvIsProd check env is production ? local and test will drop database & import test data
func ExecSQLFile ¶ added in v0.7.5
ExecSQLFile danger!!! just for importing test data.
func Migrate ¶ added in v0.4.3
Migrate Run new bindataInstance and UP
func NewAPIError ¶ added in v0.4.0
NewAPIError new api error
func PageQueryParamters ¶
func PageQueryParamters(req *restful.Request) (pageIndex, pageSize uint)
PageQueryParamters get page params from request
func RedisClient ¶ added in v0.8.0
func RedisClient() *redis.Client
RedisClient get redis client return for simple or sentinel(failover)mode
func Validate ¶ added in v0.2.0
func Validate() *validator.Validate
Validate validate single instance
func ValidateEntity ¶ added in v0.4.0
func ValidateEntity(entity interface{}) error
ValidateEntity validate entity
func ValidateEntityAndWriteResp ¶ added in v0.5.4
func ValidateEntityAndWriteResp(res *restful.Response, entity interface{}, apiErr *apierrors.APIError) error
ValidateEntityAndWriteResp validate entity and write header and error as entity
func ValidateTranslator ¶ added in v0.4.0
func ValidateTranslator() ut.Translator
ValidateTranslator validate trans
Types ¶
type BaseController ¶ added in v0.4.4
type BaseController struct { }
BaseController has some basic methods
func (BaseController) ValidatePageableParams ¶ added in v0.4.4
func (bc BaseController) ValidatePageableParams(req *restful.Request, res *restful.Response) (pageable *Pageable, ok bool)
ValidatePageableParams validate pagination params return paable struct
func (BaseController) ValidateResourceID ¶ added in v0.4.4
func (bc BaseController) ValidateResourceID(req *restful.Request, res *restful.Response, IDKey string) (ID uint, ok bool)
ValidateResourceID validate REST resource ID in pathparam and return it if validated.
type BaseDO ¶ added in v0.5.1
type BaseDO struct { ID uint `gorm:"primary_key" json:"id"` // primary key CreatedAt time.Time `json:"created_at,omitempty"` // created time UpdatedAt time.Time `json:"updated_at,omitempty"` //updated time DeletedAt *time.Time `sql:"index" json:"deleted_at,omitempty"` //deleted time }
Model gorm model
type BaseDTO ¶ added in v0.5.1
type BaseDTO struct { ID uint `json:"id,omitempty" description:"资源ID"` CreatedAt JSONTime `json:"created_at,omitempty" description:"创建日期"` UpdatedAt JSONTime `json:"updated_at,omitempty" description:"更新日期"` }
BaseDTO Data Transfer Object
type BaseResource ¶ added in v0.4.5
type BaseResource struct {
BaseController
}
BaseResource RESTful webservice name ,alias BaseController.
type ComplexBaseDO ¶ added in v0.5.1
type ComplexBaseDO struct { BaseDO Version uint `json:"version"` //version opt lock Addition string `json:"addition,omitempty"` }
ComplexBaseDO gorm model composed Model add Addition
type EmptyRespEntity ¶ added in v0.5.4
EmptyRespEntity 空响应体
type Entity ¶ added in v0.3.0
Entity response entity
type JSONDate ¶
JSONDate 格式化输出时间
type JSONTime ¶
JSONTime 格式化输出时间
type MultiDBSource ¶ added in v0.6.0
type MultiDBSource struct {
// contains filtered or unexported fields
}
func (MultiDBSource) Size ¶ added in v0.6.0
func (s MultiDBSource) Size() int
Size get db connection size
type Page ¶
type Page struct { List interface{} `json:"list,omitempty"` Total uint `json:"total,omitempty"` Offset uint `json:"offset,omitempty"` Index uint `json:"page_index,omitempty"` Size uint `json:"page_size,omitempty"` Pages uint `json:"pages,omitempty"` }
Page page
type PageDTO ¶ added in v0.5.4
type PageDTO struct { Total uint `json:"total"` Index uint `json:"page_index"` Size uint `json:"page_size"` Pages uint `json:"pages"` }
PageDTO common page struct
type Pageable ¶ added in v0.4.4
Pageable 可分页参数
type Pagination ¶
type Pagination struct { Offset uint `json:"offset,omitempty"` Limit uint `json:"limit,omitempty"` Condition interface{} `json:"condition,omitempty"` }
Pagination 新建分页查询
type RespEntity ¶ added in v0.5.4
RespEntity common response entity
type Response ¶ added in v0.3.0
type Response struct {
// contains filtered or unexported fields
}
Response rest response
func NewResponse ¶ added in v0.3.1
func NewResponse(res *restful.Response) *Response
NewResponse new return
func (*Response) Created ¶ added in v0.3.0
func (re *Response) Created(entity interface{})
Created 201 return
func (*Response) Error ¶ added in v0.3.0
Error error response
type ResponseEntitySample ¶ added in v0.3.8
type ResponseEntitySample struct { ErrCode int `json:"err_code,omitempty"` ErrMsg string `json:"err_msg,omitempty"` ErrDesc string `json:"err_desc,omitempty"` Data interface{} `json:"data,omitempty"` }
ResponseEntity response entity for go-restful Writes(ResponseEntity{Data: Type{}})
func NewWriteSample ¶ added in v0.3.9
func NewWriteSample(entity interface{}) ResponseEntitySample
NewWriteSample new writesample