Documentation ¶
Index ¶
- Constants
- Variables
- func BindAll(c *gin.Context, target interface{}) error
- func CheckError(c *gin.Context, err error) bool
- func CodeToSession(code string) (string, error)
- func CreateBasicAuth(username, password string) string
- func CreateToken(payload Payload) (string, error)
- func FormatDate(date time.Time) string
- func GenToken(auth string, id ...string) string
- func GetCsvMap(filePath string) ([]map[string]string, error)
- func GetDate() string
- func GetErrorMessage(err validator.FieldError) string
- func GetIdentity(c *gin.Context) model.Identity
- func GetNSQProducer() *nsq.Producer
- func GetPaginationQuery(c *gin.Context) (offset uint64, limit uint64, err error)
- func GetTokenString(token string) (string, error)
- func InitDialer()
- func InitValidator()
- func MakeEventActionHandler(action Action, event *model.Event, identity model.Identity) *eventActionHandler
- func ParseTokenWithJWKS(jwksURL string, token string) (*jwt.Token, *jwt.RegisteredClaims, error)
- func Prefixer(prefix string, columns []string) []string
- func ReadCsvFile(filePath string) ([][]string, error)
- func RollbackOnErr(err error, conn *sqlx.Tx)
- func SendMail(message *gomail.Message) error
- func SetColumnPrefix(prefix string, column string) string
- func Upload(name string, reader io.Reader) (string, error)
- type Action
- type Claims
- type ContextLogger
- type MockDB
- type NSQHookForError
- type Payload
- type ResponseBody
- type ServiceError
Constants ¶
const ( Open string = "open" Cancelled string = "cancelled" Accepted string = "accepted" Committed string = "committed" Closed string = "closed" )
const IMAGE_NAME string = "test_db"
const RESOURCE_NAME string = "test_db"
const SQL_FILE string = "saturday.sql"
Variables ¶
var EventTopic = os.Getenv("EVENT_TOPIC")
var LogTopic = os.Getenv("LOG_TOPIC")
var Logger = getLogger()
var NSQProducer *nsq.Producer
Functions ¶
func CheckError ¶
check error type if error is not nil, return true and handle accordingly, else return false
func CodeToSession ¶
func CreateBasicAuth ¶
func CreateToken ¶
func FormatDate ¶
func GenToken ¶
this is used for testing "INVALID" to gen invalid token "EXPIRED" to gen expired token "NONE" return empty token
func GetErrorMessage ¶
func GetErrorMessage(err validator.FieldError) string
func GetNSQProducer ¶
func GetNSQProducer() *nsq.Producer
func GetPaginationQuery ¶
func GetTokenString ¶
func InitDialer ¶
func InitDialer()
func InitValidator ¶
func InitValidator()
func MakeEventActionHandler ¶
func ParseTokenWithJWKS ¶
func ReadCsvFile ¶
ReadCsvFile reads a csv file and returns a slice of records
func RollbackOnErr ¶
func SetColumnPrefix ¶
Types ¶
type Claims ¶
type Claims struct { jwt.StandardClaims Payload }
func ParseToken ¶
parse a jwt token, which should begin with "`Bearer `"
type MockDB ¶
type MockDB struct {
// contains filtered or unexported fields
}
MockDB is a mock database for testing. Use MakeMockDB to create a MockDB, and call MockDB.Start() to init resource. Under the hood, it use a docker container that runs mysql as data source. So you need to keep docker running for the test to work. You should call SetSchema() before each test to reset database schema.
func MakeMockDB ¶
assetsPath should be the relative path to the assets folder, MockDB needs to read the dockerfile located in the assets folder.
type NSQHookForError ¶
type NSQHookForError struct {
Producer *nsq.Producer
}
func (*NSQHookForError) Fire ¶
func (hook *NSQHookForError) Fire(entry *logrus.Entry) error
Fire 根据 logrus.Entry 发送消息到 NSQ
func (*NSQHookForError) Levels ¶
func (hook *NSQHookForError) Levels() []logrus.Level
Levels 返回日志级别,这里返回 ErrorLevel,FatalLevel,PanicLevel
type ResponseBody ¶
type ResponseBody struct { Message string `json:"message"` Errors []detailError `json:"errors,omitempty"` }
type ServiceError ¶
type ServiceError struct { HttpStatus int Body ResponseBody // contains filtered or unexported fields }
func IsServiceError ¶
func IsServiceError(err error) (ServiceError, bool)
func MakeInternalServerError ¶
func MakeInternalServerError() ServiceError
func MakeServiceError ¶
func MakeServiceError(HttpStatus int) ServiceError
func MakeValidationError ¶
func MakeValidationError(resource string, err error) ServiceError
parse error from validator return a *ServiceError with status code http.StatusUnprocessableEntity
func (ServiceError) AddDetailError ¶
func (serviceError ServiceError) AddDetailError(resource string, field string, error string) ServiceError
func (ServiceError) Build ¶
func (error ServiceError) Build() (int, interface{})
func (ServiceError) SetMessage ¶
func (serviceError ServiceError) SetMessage(message string) ServiceError
func (ServiceError) SetStatus ¶
func (serviceError ServiceError) SetStatus(status int) ServiceError