fiberextend

package module
v0.0.0-...-e8366a0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2023 License: Apache-2.0 Imports: 39 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 Redis *redis.Client
View Source
var Validator *validator.Validate

Functions

func Bool

func Bool(src bool) *bool

func Int

func Int(src int) *int

func RunCommand

func RunCommand() (string, bool)

func String

func String(src string) *string

func ValidateMatch

func ValidateMatch(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 IDBConfig

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

type IError

type IError struct {
	Code    string `json:"code"`
	Field   string `json:"field,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
	Validator *validator.Validate
}
var Ex *IFiberEx

func New

func New(config IFiberExConfig) *IFiberEx

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) 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) RequestParser

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

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) 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(errors validator.ValidationErrors) []IError

type IFiberExConfig

type IFiberExConfig struct {
	// 実行モード
	DevMode  *bool
	TestMode *bool
	// 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
	// ページング処理
	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
}

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 IFiberExTest

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

	Redis  *miniredis.Miniredis
	Tester *apitest.APITest
	// 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) 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        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 {
	Method ITestMethod        // assertしたい内容
	Want   interface{}        // 期待値
	Path   string             // jsonpath `$.id`
	Store  func() interface{} // データの取得 pathが指定されていない場合に使用
}

func (*ITestCase) ApiAssert

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

func (*ITestCase) Assert

func (p *ITestCase) Assert() error

func (*ITestCase) Error

func (p *ITestCase) Error(message string) 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{}
}

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
⌂ 换网址