Skip to content

Commit

Permalink
统一格式
Browse files Browse the repository at this point in the history
  • Loading branch information
XIAHUALOU committed Oct 28, 2022
1 parent b9b523d commit d98fe70
Show file tree
Hide file tree
Showing 22 changed files with 154 additions and 154 deletions.
8 changes: 4 additions & 4 deletions fit/Annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ type Value struct {
tag reflect.StructTag
}

func (this *Value) SetTag(tag reflect.StructTag) {
this.tag = tag
func (self *Value) SetTag(tag reflect.StructTag) {
self.tag = tag
}

func (this *Value) String() string {
get_prefix := this.tag.Get("prefix")
func (self *Value) String() string {
get_prefix := self.tag.Get("prefix")
if get_prefix == "" {
return ""
}
Expand Down
6 changes: 3 additions & 3 deletions fit/ExprParser.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ type Expr string //表达式类型
// 可比较表达式 解析类, 譬如a>3 b!=4 a!=n a>3 [gt .a 3]
type ComparableExpr string

func (this ComparableExpr) filter() string {
func (self ComparableExpr) filter() string {
reg, err := regexp.Compile(ComparePattern)
if err != nil {
return ""
}
ret := reg.FindStringSubmatch(string(this))
ret := reg.FindStringSubmatch(string(self))
if ret != nil && len(ret) == 4 {
token := getCompareToken(ret[2])
if token == "" {
Expand All @@ -38,7 +38,7 @@ func (this ComparableExpr) filter() string {
// 普通表达式,如 .user.Age .user.Info(101)
type SimpleExpr string

func (this SimpleExpr) filter() string {
func (self SimpleExpr) filter() string {
// 处理括号里面的参数
return ""
}
Expand Down
4 changes: 2 additions & 2 deletions fit/ExprParser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "testing"
func TestComparableExpr_filter(t *testing.T) {
tests := []struct {
name string
this ComparableExpr
self ComparableExpr
want string
}{
{"w1", ComparableExpr("a>3"), "gt .a 3"},
Expand All @@ -19,7 +19,7 @@ func TestComparableExpr_filter(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.this.filter(); got != tt.want {
if got := tt.self.filter(); got != tt.want {
t.Errorf("ComparableExpr.filter() = %v, want %v", got, tt.want)
}
})
Expand Down
16 changes: 8 additions & 8 deletions fit/FairingHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@ func NewFairingHandler() *FairingHandler {
return &FairingHandler{}
}

func (this *FairingHandler) AddFairing(f ...Fairing) {
func (self *FairingHandler) AddFairing(f ...Fairing) {
if f != nil && len(f) > 0 {

this.fairings = append(this.fairings, f...)
self.fairings = append(self.fairings, f...)
}

}
func (this *FairingHandler) before(ctx *gin.Context) {
for _, f := range this.fairings {
func (self *FairingHandler) before(ctx *gin.Context) {
for _, f := range self.fairings {
err := f.OnRequest(ctx)
if err != nil {
Throw(err.Error(), 400, ctx)
}
}
}
func (this *FairingHandler) after(ctx *gin.Context, ret interface{}) interface{} {
func (self *FairingHandler) after(ctx *gin.Context, ret interface{}) interface{} {
var result = ret
for _, f := range this.fairings {
for _, f := range self.fairings {
r, err := f.OnResponse(result)
if err != nil {
Throw(err.Error(), 400, ctx)
Expand All @@ -49,8 +49,8 @@ func (this *FairingHandler) after(ctx *gin.Context, ret interface{}) interface{}
}
return result
}
func (this *FairingHandler) handlerFairing(responder Responder, ctx *gin.Context) interface{} {
this.before(ctx)
func (self *FairingHandler) handlerFairing(responder Responder, ctx *gin.Context) interface{} {
self.before(ctx)
var ret interface{}
innerNode := getInnerRouter().getRoute(ctx.Request.Method, ctx.Request.URL.Path)
var innerFairingHandler *FairingHandler
Expand Down
68 changes: 34 additions & 34 deletions fit/Goft.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,103 +49,103 @@ func Ignite(ginMiddlewares ...gin.HandlerFunc) *FitGin {
}
return g
}
func (this *FitGin) Launch() {
func (self *FitGin) Launch() {
var port int32 = 8080
if config := Injector.BeanFactory.Get((*SysConfig)(nil)); config != nil {
port = config.(*SysConfig).Server.Port
}
this.applyAll()
self.applyAll()
getCronTask().Start()
this.Run(fmt.Sprintf(":%d", port))
self.Run(fmt.Sprintf(":%d", port))
}
func (this *FitGin) LaunchWithPort(port int) {
func (self *FitGin) LaunchWithPort(port int) {

this.applyAll()
self.applyAll()
getCronTask().Start()
this.Run(fmt.Sprintf(":%d", port))
self.Run(fmt.Sprintf(":%d", port))
}
func (this *FitGin) Handle(httpMethod, relativePath string, handler interface{}) *FitGin {
func (self *FitGin) Handle(httpMethod, relativePath string, handler interface{}) *FitGin {
if h := Convert(handler); h != nil {
methods := strings.Split(httpMethod, ",")
for _, method := range methods {
getInnerRouter().addRoute(method, this.getPath(relativePath), h) // for future
this.g.Handle(method, relativePath, h)
getInnerRouter().addRoute(method, self.getPath(relativePath), h) // for future
self.g.Handle(method, relativePath, h)
}

}
return this
return self
}
func (this *FitGin) getPath(relativePath string) string {
g := "/" + this.currentGroup
func (self *FitGin) getPath(relativePath string) string {
g := "/" + self.currentGroup
if g == "/" {
g = ""
}
g = g + relativePath
g = strings.Replace(g, "//", "/", -1)
return g
}
func (this *FitGin) HandleWithFairing(httpMethod, relativePath string, handler interface{}, fairings ...Fairing) *FitGin {
func (self *FitGin) HandleWithFairing(httpMethod, relativePath string, handler interface{}, fairings ...Fairing) *FitGin {
if h := Convert(handler); h != nil {
methods := strings.Split(httpMethod, ",")
for _, f := range fairings {
Injector.BeanFactory.Apply(f)
}
for _, method := range methods {
getInnerRouter().addRoute(method, this.getPath(relativePath), fairings) //for future
this.g.Handle(method, relativePath, h)
getInnerRouter().addRoute(method, self.getPath(relativePath), fairings) //for future
self.g.Handle(method, relativePath, h)
}

}
return this
return self
}

// 注册中间件
func (this *FitGin) Attach(f ...Fairing) *FitGin {
func (self *FitGin) Attach(f ...Fairing) *FitGin {
for _, f1 := range f {
Injector.BeanFactory.Set(f1)
}
getFairingHandler().AddFairing(f...)
return this
return self
}

func (this *FitGin) Beans(beans ...Bean) *FitGin {
func (self *FitGin) Beans(beans ...Bean) *FitGin {
for _, bean := range beans {
this.exprData[bean.Name()] = bean
self.exprData[bean.Name()] = bean
Injector.BeanFactory.Set(bean)
}
return this
return self
}
func (this *FitGin) Config(cfgs ...interface{}) *FitGin {
func (self *FitGin) Config(cfgs ...interface{}) *FitGin {
Injector.BeanFactory.Config(cfgs...)
return this
return self
}
func (this *FitGin) applyAll() {
func (self *FitGin) applyAll() {
for t, v := range Injector.BeanFactory.GetBeanMapper() {
if t.Elem().Kind() == reflect.Struct {
Injector.BeanFactory.Apply(v.Interface())
}
}
}

func (this *FitGin) Mount(group string, classes ...IClass) *FitGin {
this.g = this.Group(group)
func (self *FitGin) Mount(group string, classes ...IClass) *FitGin {
self.g = self.Group(group)
for _, class := range classes {
this.currentGroup = group
class.Build(this)
//this.beanFactory.inject(class)
this.Beans(class)
self.currentGroup = group
class.Build(self)
//self.beanFactory.inject(class)
self.Beans(class)
}
return this
return self
}

// 0/3 * * * * * //增加定时任务
func (this *FitGin) Task(cron string, expr interface{}) *FitGin {
func (self *FitGin) Task(cron string, expr interface{}) *FitGin {
var err error
if f, ok := expr.(func()); ok {
_, err = getCronTask().AddFunc(cron, f)
} else if exp, ok := expr.(Expr); ok {
_, err = getCronTask().AddFunc(cron, func() {
_, expErr := ExecExpr(exp, this.exprData)
_, expErr := ExecExpr(exp, self.exprData)
if expErr != nil {
log.Println(expErr)
}
Expand All @@ -155,5 +155,5 @@ func (this *FitGin) Task(cron string, expr interface{}) *FitGin {
if err != nil {
log.Println(err)
}
return this
return self
}
10 changes: 5 additions & 5 deletions fit/GoftTree.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ func NewFitGinTree() *FitGinTree {
}
return tree
}
func (this *FitGinTree) addRoute(method, path string, handlers interface{}) {
root := this.trees.get(method)
func (self *FitGinTree) addRoute(method, path string, handlers interface{}) {
root := self.trees.get(method)
if root == nil {
root = new(node)
root.fullPath = "/"
this.trees = append(this.trees, methodTree{method: method, root: root})
self.trees = append(self.trees, methodTree{method: method, root: root})
}
root.addRoute(path, handlers)
}
func (this *FitGinTree) getRoute(httpMethod, path string) nodeValue {
t := this.trees
func (self *FitGinTree) getRoute(httpMethod, path string) nodeValue {
t := self.trees
for i, tl := 0, len(t); i < tl; i++ {
if t[i].method != httpMethod {
continue
Expand Down
2 changes: 1 addition & 1 deletion fit/GormAdapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type GormAdapter struct {
*gorm.DB
}

func (this *GormAdapter) Name() string {
func (self *GormAdapter) Name() string {
return "GormAdapter"
}
func NewGormAdapter() *GormAdapter {
Expand Down
24 changes: 12 additions & 12 deletions fit/Responder.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,26 @@ func Convert(handler interface{}) gin.HandlerFunc {

type StringResponder func(*gin.Context) string

func (this StringResponder) RespondTo() gin.HandlerFunc {
func (self StringResponder) RespondTo() gin.HandlerFunc {
return func(context *gin.Context) {
context.String(200, getFairingHandler().handlerFairing(this, context).(string))
context.String(200, getFairingHandler().handlerFairing(self, context).(string))
}
}

type Json interface{}
type JsonResponder func(*gin.Context) Json

func (this JsonResponder) RespondTo() gin.HandlerFunc {
func (self JsonResponder) RespondTo() gin.HandlerFunc {
return func(context *gin.Context) {
context.JSON(200, getFairingHandler().handlerFairing(this, context))
context.JSON(200, getFairingHandler().handlerFairing(self, context))
}
}

type SqlQueryResponder func(*gin.Context) Query

func (this SqlQueryResponder) RespondTo() gin.HandlerFunc {
func (self SqlQueryResponder) RespondTo() gin.HandlerFunc {
return func(context *gin.Context) {
getQuery := getFairingHandler().handlerFairing(this, context).(Query)
getQuery := getFairingHandler().handlerFairing(self, context).(Query)
ret, err := queryForMapsByInterface(getQuery)
if err != nil {
panic(err)
Expand All @@ -69,9 +69,9 @@ func (this SqlQueryResponder) RespondTo() gin.HandlerFunc {

type SqlResponder func(*gin.Context) SimpleQuery

func (this SqlResponder) RespondTo() gin.HandlerFunc {
func (self SqlResponder) RespondTo() gin.HandlerFunc {
return func(context *gin.Context) {
getSql := getFairingHandler().handlerFairing(this, context).(SimpleQuery)
getSql := getFairingHandler().handlerFairing(self, context).(SimpleQuery)
ret, err := queryForMaps(string(getSql), nil, []interface{}{}...)
if err != nil {
panic(err)
Expand All @@ -83,18 +83,18 @@ func (this SqlResponder) RespondTo() gin.HandlerFunc {
type Void struct{}
type VoidResponder func(ctx *gin.Context) Void

func (this VoidResponder) RespondTo() gin.HandlerFunc {
func (self VoidResponder) RespondTo() gin.HandlerFunc {
return func(context *gin.Context) {
getFairingHandler().handlerFairing(this, context)
getFairingHandler().handlerFairing(self, context)
}
}

// Deprecated: 暂时不提供View的解析
type View string
type ViewResponder func(*gin.Context) View

func (this ViewResponder) RespondTo() gin.HandlerFunc {
func (self ViewResponder) RespondTo() gin.HandlerFunc {
return func(context *gin.Context) {
context.HTML(200, string(this(context))+".html", context.Keys)
context.HTML(200, string(self(context))+".html", context.Keys)
}
}

0 comments on commit d98fe70

Please sign in to comment.