fiberextend

package module
v0.1.43 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: Apache-2.0 Imports: 48 Imported by: 0

README

fiberextend

Documentation

Index

Constants

View Source
const MailFormat string = `From: %s
To: %s
%s
MIME-Version: 1.0
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: base64

%s`

Variables

View Source
var DB *gorm.DB
View Source
var ES *elasticsearch.Client
View Source
var JobAlive = false
View Source
var LocalFilePath = ""
View Source
var Redis *redis.Client
View Source
var Sentry *sentry.Client
View Source
var Validator *validator.Validate

Functions

func Atoi added in v0.1.32

func Atoi(src string) int

stringをintに変換

func Atoi64 added in v0.1.32

func Atoi64(src string) int64

stringをint64に変換

func Bool

func Bool(src bool) *bool

func BoolToUint added in v0.1.32

func BoolToUint(ok bool) uint

bool型をint型に変換

func ConvertCamelCase added in v0.1.32

func ConvertCamelCase(src string) string

キャメルケースに変換

func ConvertPascalCase added in v0.1.32

func ConvertPascalCase(src string) string

パスカルケースに変換

func ConvertSnakeCase added in v0.1.32

func ConvertSnakeCase(src string) string

スネークケースに変換

func ConvertStruct added in v0.1.32

func ConvertStruct(src interface{}, out interface{}) error

jsonを使って異なる型に変換

func DeepCopy added in v0.1.32

func DeepCopy(src interface{}, out interface{}) error

jsonを使ってデータを複製

func GetJsonTag added in v0.1.16

func GetJsonTag[T comparable](src T, field string) string

func InitErrors added in v0.1.42

func InitErrors(path string)

func Int

func Int(src int) *int

func Int64 added in v0.1.32

func Int64(src int64) *int64

func Itoa added in v0.1.32

func Itoa(src int64) string

int64をstringに変換

func JsonPath added in v0.1.38

func JsonPath(src *simplejson.Json, path string) (result interface{})

simplejsonから指定のパスの値を取得

func MapToValueArray added in v0.1.32

func MapToValueArray(src map[string]interface{}) []interface{}

map型をarray型に変換

func Match added in v0.1.33

func Match(reg, str string) bool

正規表現共通関数

func NewErrors added in v0.1.42

func NewErrors(err error) error

func Now added in v0.1.32

func Now() *time.Time

現在時刻をポインタで取得

func Recover added in v0.1.35

func Recover(ex *IFiberEx)

リカバー時にログを出力する

func RequestParser added in v0.1.16

func RequestParser[T comparable](ex *IFiberEx, c *fiber.Ctx, params *T) bool

func RunCommand

func RunCommand() (string, []string, bool)

func StackTrace added in v0.1.42

func StackTrace() []string

func String

func String(src string) *string

func StructPath added in v0.1.35

func StructPath(src interface{}, path string) (result interface{})

構造体から指定のパスの値を取得

func ToJson added in v0.1.32

func ToJson(src interface{}) string

型をjson文字列に変換

func ToPrettyJson added in v0.1.32

func ToPrettyJson(src interface{}) string

型を整形したjson文字列に変換

func UuidBase64Decoding added in v0.1.32

func UuidBase64Decoding(src string) (string, error)

base64にエンコードされたUUIDをUUID形式に変換

func UuidBase64Encoding added in v0.1.32

func UuidBase64Encoding(src string) (string, error)

UUIDをbase64に変換

func ValidateMatch

func ValidateMatch(fl validator.FieldLevel) bool

func ValidatePassword added in v0.1.33

func ValidatePassword(fl validator.FieldLevel) bool

Types

type ErrorCode

type ErrorCode int
const (
	E00500 ErrorCode = iota
	E40001
	E99999
)

func (ErrorCode) Errors

func (p ErrorCode) Errors() []IError

type Errors added in v0.1.42

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

func (*Errors) Error added in v0.1.42

func (p *Errors) Error() string

func (*Errors) String added in v0.1.42

func (p *Errors) String() string

func (*Errors) Trace added in v0.1.42

func (p *Errors) Trace() []string

type FilterString added in v0.1.32

type FilterString string

json化時に文字列をフィルタリングする

func FilterStrings added in v0.1.32

func FilterStrings(src string) FilterString

func (FilterString) MarshalJSON added in v0.1.32

func (p FilterString) MarshalJSON() ([]byte, error)

func (FilterString) String added in v0.1.32

func (p FilterString) String() string

func (*FilterString) UnmarshalJSON added in v0.1.32

func (p *FilterString) UnmarshalJSON(data []byte) error

type IDBConfig

type IDBConfig struct {
	Config     *gorm.Config
	User       string
	Pass       string
	Addr       string
	DBName     string
	IsPostgres *bool
}

type IError

type IError struct {
	Code    string `json:"code"`
	Field   string `json:"field,omitempty"`
	Param   string `json:"param,omitempty"`
	Message string `json:"message"`
}

type IFiberEx

type IFiberEx struct {
	NodeId    string
	Config    IFiberExConfig
	App       *fiber.App
	Log       *zap.Logger
	DB        *gorm.DB
	Redis     *redis.Client
	ES        *elasticsearch.Client
	Sentry    *sentry.Client
	Validator *validator.Validate
}
var Ex *IFiberEx

func New

func New(config IFiberExConfig) *IFiberEx

func (*IFiberEx) ApiErrorLogFields added in v0.1.42

func (p *IFiberEx) ApiErrorLogFields(c *fiber.Ctx, err error, fields ...zapcore.Field) []zapcore.Field

func (*IFiberEx) ApiLogFields added in v0.1.31

func (p *IFiberEx) ApiLogFields(c *fiber.Ctx, fields ...zapcore.Field) []zapcore.Field

func (*IFiberEx) CatchPreparedStatementsError added in v0.1.26

func (p *IFiberEx) CatchPreparedStatementsError(err error)

func (*IFiberEx) ClearPreparedStatements added in v0.1.26

func (p *IFiberEx) ClearPreparedStatements()

func (*IFiberEx) DefaultErrorHandler

func (p *IFiberEx) DefaultErrorHandler() func(*fiber.Ctx, error) error

func (*IFiberEx) ExecuteTemplate

func (p *IFiberEx) ExecuteTemplate(out io.Writer, src string, values interface{}) error

func (*IFiberEx) GetRedisJson

func (p *IFiberEx) GetRedisJson(rs interface{}, key string) error

json型から変換して取得

func (*IFiberEx) IpAddr

func (p *IFiberEx) IpAddr() string

func (*IFiberEx) JobEnqueue

func (p *IFiberEx) JobEnqueue(queue string, class string, args interface{}) error

func (*IFiberEx) JobEnqueueAt

func (p *IFiberEx) JobEnqueueAt(queue string, class string, at time.Time, args interface{}) error

func (*IFiberEx) JobEnqueueIn

func (p *IFiberEx) JobEnqueueIn(queue string, class string, in float64, args interface{}) error

func (*IFiberEx) JobRun

func (p *IFiberEx) JobRun(jobs ...IJob)

func (*IFiberEx) LogCaller added in v0.1.11

func (p *IFiberEx) LogCaller() zapcore.Field

func (*IFiberEx) LogError added in v0.1.4

func (p *IFiberEx) LogError(err error, fields ...zap.Field)

func (*IFiberEx) LogFatal added in v0.1.4

func (p *IFiberEx) LogFatal(err error, fields ...zap.Field)

func (*IFiberEx) LogInfo added in v0.1.31

func (p *IFiberEx) LogInfo(msg string, fields ...zap.Field)

func (*IFiberEx) LogTrace added in v0.1.42

func (p *IFiberEx) LogTrace(err error, fields ...zap.Field) *zap.Logger

func (*IFiberEx) LogWarn added in v0.1.4

func (p *IFiberEx) LogWarn(err error, fields ...zap.Field)

func (*IFiberEx) Mail

func (p *IFiberEx) Mail(to []string, subject string, body string, values interface{}) error

func (*IFiberEx) MetaMiddleware

func (p *IFiberEx) MetaMiddleware() func(*fiber.Ctx) error

func (*IFiberEx) NewApp

func (p *IFiberEx) NewApp() *fiber.App

func (*IFiberEx) NewJob

func (p *IFiberEx) NewJob(jobs ...*IJob)

func (*IFiberEx) NewMeta

func (p *IFiberEx) NewMeta(c *fiber.Ctx) *IMeta

func (*IFiberEx) Printf added in v0.1.11

func (p *IFiberEx) Printf(base string, args ...interface{})

func (*IFiberEx) Println added in v0.1.11

func (p *IFiberEx) Println(args ...interface{})

func (*IFiberEx) ReconnectDB added in v0.1.26

func (p *IFiberEx) ReconnectDB()

func (*IFiberEx) RequestParser deprecated

func (p *IFiberEx) RequestParser(c *fiber.Ctx, params interface{}) bool

Deprecated: should not be used

func (*IFiberEx) Result

func (p *IFiberEx) Result(c *fiber.Ctx, code int, results ...interface{}) error

func (*IFiberEx) ResultError

func (p *IFiberEx) ResultError(c *fiber.Ctx, code int, err error, errors ...IError) error

func (*IFiberEx) SentryScope added in v0.1.13

func (p *IFiberEx) SentryScope(fields []zap.Field) *sentry.Scope

func (*IFiberEx) SetRedisJson

func (p *IFiberEx) SetRedisJson(key string, src interface{}, expire time.Duration) error

json型に変換して保存

func (*IFiberEx) SimpleValidation

func (p *IFiberEx) SimpleValidation(src interface{}, field string, tag string) []IError

func (*IFiberEx) Validation

func (p *IFiberEx) Validation(src interface{}) []IError

func (*IFiberEx) ValidationParser

func (p *IFiberEx) ValidationParser(src interface{}, errors validator.ValidationErrors) []IError

type IFiberExConfig

type IFiberExConfig struct {
	// 実行モード
	DevMode  *bool
	TestMode *bool
	// 内部パラメータ
	SecretToken   string
	TokenExpireAt time.Duration
	// fiber初期化パラメータ
	IconFile         *string
	IconUrl          *string
	CorsOrigin       *string
	CorsHeaders      *string
	CaseSensitive    *bool
	Concurrency      *int
	DisableKeepalive *bool
	ErrorHandler     func(*fiber.Ctx, error) error
	AppName          *string
	BodyLimit        *int
	// サービスホスト
	Host string
	// ページング処理
	PagePer *int
	// データベース接続
	UseDB    bool
	DBConfig *IDBConfig
	// キャッシュサーバ接続
	UseRedis     bool
	RedisOptions *redis.Options
	// elasticsearch接続
	UseES    bool
	ESConfig *elasticsearch.Config
	// SMTP
	SmtpUseMd5 bool
	SmtpFrom   string
	SmtpAddr   string
	SmtpUser   *string
	SmtpPass   *string
	// Job
	JobAddr     string
	JobDatabase int
	JobPool     int
	JobProcess  int
	// Sentry
	SentryDsn   *string
	SentryScope *sentry.Scope
	SentryEnv   string
	// Option 任意のパラメータの格納
	Options *IFiberExConfigOption
}

func (*IFiberExConfig) NewDB

func (p *IFiberExConfig) NewDB() *gorm.DB

func (*IFiberExConfig) NewES

func (p *IFiberExConfig) NewES() *elasticsearch.Client

func (*IFiberExConfig) NewRedis

func (p *IFiberExConfig) NewRedis() *redis.Client

type IFiberExConfigOption added in v0.1.8

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

func NewIFiberExConfigOption added in v0.1.8

func NewIFiberExConfigOption(src map[string]interface{}) *IFiberExConfigOption

func (*IFiberExConfigOption) GetInt added in v0.1.8

func (p *IFiberExConfigOption) GetInt(key string) int

func (*IFiberExConfigOption) GetInt64 added in v0.1.8

func (p *IFiberExConfigOption) GetInt64(key string) int64

func (*IFiberExConfigOption) GetString added in v0.1.8

func (p *IFiberExConfigOption) GetString(key string) string

type IFiberExTest

type IFiberExTest struct {
	Ex  *IFiberEx
	App *fiber.App

	Redis *miniredis.Miniredis
	// contains filtered or unexported fields
}

func NewTest

func NewTest(t *testing.T, config IFiberExConfig) *IFiberExTest

func (*IFiberExTest) Api

func (p *IFiberExTest) Api(message string, request *ITestRequest, status int, asserts ...*ITestCase)

func (*IFiberExTest) DryJobs

func (p *IFiberExTest) DryJobs(names ...string)

func (*IFiberExTest) Exec added in v0.1.35

func (p *IFiberExTest) Exec(it string, exec func() interface{}, asserts ...*ITestCase)

func (*IFiberExTest) It

func (p *IFiberExTest) It(message string)

func (*IFiberExTest) Job

func (p *IFiberExTest) Job(it string, before func(), job func(), asserts ...*ITestCase)

func (*IFiberExTest) Routes

func (p *IFiberExTest) Routes(routes func(*IFiberEx))

func (*IFiberExTest) Run

func (p *IFiberExTest) Run(it string, tests func())

type IJob

type IJob struct {
	Name        string                 // ジョブ名
	Proc        func(msg *workers.Msg) // 処理内容
	Concurrency int                    // 優先度
	Schedule    *string                // cron形式 https://github.com/bamzi/jobrunner
	Class       string                 // スケジュール実行時のクラス名
	Args        func() interface{}     // スケジュール実行時のパラメータ
	Middlewares []workers.Action       // ジョブ特有のアクション
}

func (IJob) Run

func (p IJob) Run()

type IMeta

type IMeta struct {
	Total   int64  `json:"total,omitempty"`   // トータル件数
	Page    int    `json:"page,omitempty"`    // ページ数
	Current int    `json:"current,omitempty"` // 現在のページ
	Elapsed string `json:"elapsed,omitempty"` // 所要時間
}

type IRequestPaging

type IRequestPaging struct {
	Page *int `json:"page,omitempty"` // 表示ページ(1~)
	Per  *int `json:"per,omitempty"`  // 表示数
}

type IResponse

type IResponse struct {
	Meta    *IMeta        `json:"meta,omitempty"`
	Result  interface{}   `json:"result,omitempty"`
	Results []interface{} `json:"results,omitempty"`
	Errors  []IError      `json:"error,omitempty"`
}

type ITestCase

type ITestCase struct {
	It     string                               // テストケースの説明
	Method ITestMethod                          // assertしたい内容
	Want   interface{}                          // 期待値
	Path   string                               // jsonpath `$.id`
	Store  func() interface{}                   // データの取得 pathが指定されていない場合に使用
	Result func(result interface{}) interface{} // データの取得して加工する
	// contains filtered or unexported fields
}

func (*ITestCase) ApiAssert

func (p *ITestCase) ApiAssert() func(*http.Response, *http.Request) error

func (*ITestCase) ApiAssertOld deprecated added in v0.1.38

func (p *ITestCase) ApiAssertOld() func(*http.Response, *http.Request) error

Deprecated: should not be used

func (*ITestCase) ResultAssert added in v0.1.35

func (p *ITestCase) ResultAssert() error

func (*ITestCase) StoreAssert added in v0.1.35

func (p *ITestCase) StoreAssert() error

type ITestMethod

type ITestMethod int
const (
	TestMethodEqual ITestMethod = iota
	TestMethodNotEqual
	TestMethodContains
	TestMethodPresent
	TestMethodNotPresent
	TestMethodMatches
	TestMethodLen
	TestMethodGreaterThan
	TestMethodLessThan
)

type ITestRequest

type ITestRequest struct {
	Method  string
	Path    string
	Headers map[string]string
	Body    interface{}
	Query   *map[string]string
	Debug   bool
}

func (ITestRequest) Call

func (p ITestRequest) Call(test *apitest.APITest) *apitest.Request

func (*ITestRequest) ToString

func (p *ITestRequest) ToString() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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