Skip to content

Commit

Permalink
fix: errors import
Browse files Browse the repository at this point in the history
  • Loading branch information
2637309949 committed Oct 29, 2021
1 parent f5c4c58 commit ffd2d98
Show file tree
Hide file tree
Showing 527 changed files with 6,225 additions and 253 deletions.
12 changes: 5 additions & 7 deletions cmd/dolphin/template/assets/app.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ import (
"github.com/spf13/viper"
"github.com/2637309949/dolphin/platform/{{$.Viper.GetString "dir.api" }}"
"github.com/2637309949/dolphin/platform/util"
"github.com/2637309949/dolphin/platform/util/errors"
)

// vars defined TODO
var (
App *Dolphin
Run func() error
Run func()
)

type (
Expand Down Expand Up @@ -55,16 +56,13 @@ func (dol *Dolphin) Reflesh() error {
}

// Run defined TODO
func (dol *Dolphin) Run() error {
func (dol *Dolphin) Run() {
if err := dol.Reflesh(); err != nil {
logrus.Errorln(err)
return err
panic(fmt.Errorf("%v\n%v", err, string(errors.Wrap(err, 2).Stack())))
}
if err := dol.LifeCycle(context.Background()); err != nil {
logrus.Errorln(err)
return err
panic(fmt.Errorf("%v\n%v", err, string(errors.Wrap(err, 2).Stack())))
}
return nil
}

// Use defined TODO
Expand Down
12 changes: 11 additions & 1 deletion cmd/dolphin/template/assets/bean.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,14 @@ type {{.Bean.ToUpperCase .Bean.Name}} struct {
// {{.Desc}}
{{.ToUpperCase .Name}} {{.SRef .Type}} `json:"{{- if ne .JSON ""}}{{.JSON}}{{- else}}{{.Name}}{{- end}}" xml:"{{.Name}}"{{- if ne .Example ""}} example:"{{.Example}}"{{- end}}`
{{- end}}
}
}

func (r *{{.Bean.ToUpperCase .Bean.Name}}) Marshal() ([]byte, error) {
return json.Marshal(r)
}

func Unmarshal{{.Bean.ToUpperCase .Bean.Name}}(data []byte) ({{.Bean.ToUpperCase .Bean.Name}}, error) {
var r {{.Bean.ToUpperCase .Bean.Name}}
err := json.Unmarshal(data, &r)
return r, err
}
8 changes: 6 additions & 2 deletions cmd/dolphin/template/assets/errors.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
package errors

import (
"errors"
"github.com/go-errors/errors"
)

// errors const defined TODO
var (
ErrNotFound = errors.New("not found")
)
)

func Wrap(e interface{}, skip int) *errors.Error {
return errors.Wrap(e, skip)
}
63 changes: 7 additions & 56 deletions cmd/dolphin/template/assets/svc.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,13 @@ import (
"github.com/gin-gonic/gin"
)

type (
// Store defined TODO
Store interface {
Get(key string, value interface{}) error
Set(key string, value interface{}, expire time.Duration) error
Add(key string, value interface{}, expire time.Duration) error
Replace(key string, data interface{}, expire time.Duration) error
Delete(key string) error
Increment(key string, data uint64) (uint64, error)
Decrement(key string, data uint64) (uint64, error)
Flush() error
}

// Report defined TODO
Report interface {
Check(*http.Request) bool
PageExport(*xorm.Engine, string, string, string, map[string]interface{}, ...svc.Formatter) (*types.ExportInfo, error)
ParseExcel(r io.Reader, sheet interface{}, header ...[]map[string]interface{}) ([]map[string]string, error)
SetOptionsetsFormat(func(interface{}) func(interface{}) interface{})
}

// DB defined TODO
DB interface {
PageSearch(*xorm.Engine, string, string, string, map[string]interface{}, ...svc.Formatter) (*types.PageList, error)
TreeSearch(*xorm.Engine, string, string, string, map[string]interface{}, ...svc.Formatter) (interface{}, error)
GetOptions(*xorm.Engine, ...string) (map[string]map[string]interface{}, error)
InRole(*xorm.Engine, string, ...string) bool
InAdmin(*xorm.Engine, string, ...string) bool
Persist(db *xorm.Session, ids ...string) (int64, error)
PersistFile(db *xorm.Session, cb func([]types.SysAttachment) error, ids ...string) (int64, error)
Remove(db *xorm.Session, ids ...string) (int64, error)
RemoveFile(db *xorm.Session, cb func([]types.SysAttachment) error, ids ...string) (int64, error)
}

// Client defined TODO
Client interface {
// Get returns *HttpRequest with GET method.
Get(url string) *client.HttpRequest
// Post returns *HttpRequest with POST method.
Post(url string) *client.HttpRequest
// Put returns *HttpRequest with PUT method.
Put(url string) *client.HttpRequest
// Delete returns *HttpRequest DELETE method.
Delete(url string) *client.HttpRequest
// Head returns *HttpRequest with HEAD method.
Head(url string) *client.HttpRequest
}

// ServiceContext defined TODO
ServiceContext struct {
Report Report
Store Store
Client Client
DB DB
}
)
// ServiceContext defined TODO
type ServiceContext struct {
Report svc.Report
Store svc.Store
Client svc.Client
DB svc.DB
}

// NewServiceContext defined TODO
func NewServiceContext(cache persistence.CacheStore) *ServiceContext {
Expand Down
10 changes: 10 additions & 0 deletions cmd/dolphin/template/assets/types.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,13 @@ type {{.Table.ToUpperCase .Table.Name}} struct {
func (m *{{.Table.ToUpperCase .Table.Name}}) TableName() string {
return "{{.Table.Name}}"
}

func (r *{{.Table.ToUpperCase .Table.Name}}) Marshal() ([]byte, error) {
return json.Marshal(r)
}

func Unmarshal{{.Table.ToUpperCase .Table.Name}}(data []byte) ({{.Table.ToUpperCase .Table.Name}}, error) {
var r {{.Table.ToUpperCase .Table.Name}}
err := json.Unmarshal(data, &r)
return r, err
}
30 changes: 15 additions & 15 deletions cmd/dolphin/template/dist/assets.go

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions examples/aisle/api/app.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions examples/aisle/api/auto.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/aisle/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.13
require (
github.com/2637309949/dolphin v1.0.67
github.com/gin-contrib/cache v1.1.0
github.com/go-errors/errors v1.0.1
github.com/mattn/go-sqlite3 v1.14.7
github.com/shopspring/decimal v1.2.0
github.com/sirupsen/logrus v1.8.1
Expand Down
2 changes: 2 additions & 0 deletions examples/aisle/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ github.com/mattn/go-sqlite3 v1.14.7 h1:fxWBnXkxfM6sRiuH3bqJ4CfzZojMOLVc0UTsTglEg
github.com/mattn/go-sqlite3 v1.14.7/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/memcachier/mc v2.0.1+incompatible h1:s8EDz0xrJLP8goitwZOoq1vA/sm0fPS4X3KAF0nyhWQ=
github.com/memcachier/mc v2.0.1+incompatible/go.mod h1:7bkvFE61leUBvXz+yxsOnGBQSZpBSPIMUQSmmSHvuXc=
github.com/memcachier/mc/v3 v3.0.3 h1:qii+lDiPKi36O4Xg+HVKwHu6Oq+Gt17b+uEiA0Drwv4=
github.com/memcachier/mc/v3 v3.0.3/go.mod h1:GzjocBahcXPxt2cmqzknrgqCOmMxiSzhVKPOe90Tpug=
github.com/miekg/dns v1.0.14 h1:9jZdLNd/P4+SfEJ0TNyxYpsK8N4GtfylBLqtbYN1sbA=
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
Expand Down
70 changes: 7 additions & 63 deletions examples/aisle/svc/svc.go
Original file line number Diff line number Diff line change
@@ -1,73 +1,17 @@
package svc

import (
"io"
"net/http"
"time"

"github.com/2637309949/dolphin/packages/xormplus/xorm"
"github.com/2637309949/dolphin/platform/svc"
"github.com/2637309949/dolphin/platform/types"
"github.com/2637309949/dolphin/platform/util/http/client"
"github.com/gin-contrib/cache/persistence"
)

type (
// Store defined TODO
Store interface {
Get(key string, value interface{}) error
Set(key string, value interface{}, expire time.Duration) error
Add(key string, value interface{}, expire time.Duration) error
Replace(key string, data interface{}, expire time.Duration) error
Delete(key string) error
Increment(key string, data uint64) (uint64, error)
Decrement(key string, data uint64) (uint64, error)
Flush() error
}

// Report defined TODO
Report interface {
Check(*http.Request) bool
PageExport(*xorm.Engine, string, string, string, map[string]interface{}, ...svc.Formatter) (*types.ExportInfo, error)
ParseExcel(r io.Reader, sheet interface{}, header ...[]map[string]interface{}) ([]map[string]string, error)
SetOptionsetsFormat(func(interface{}) func(interface{}) interface{})
}

// DB defined TODO
DB interface {
PageSearch(*xorm.Engine, string, string, string, map[string]interface{}, ...svc.Formatter) (*types.PageList, error)
TreeSearch(*xorm.Engine, string, string, string, map[string]interface{}, ...svc.Formatter) (interface{}, error)
GetOptions(*xorm.Engine, ...string) (map[string]map[string]interface{}, error)
InRole(*xorm.Engine, string, ...string) bool
InAdmin(*xorm.Engine, string, ...string) bool
Persist(db *xorm.Session, ids ...string) (int64, error)
PersistFile(db *xorm.Session, cb func([]types.SysAttachment) error, ids ...string) (int64, error)
Remove(db *xorm.Session, ids ...string) (int64, error)
RemoveFile(db *xorm.Session, cb func([]types.SysAttachment) error, ids ...string) (int64, error)
}

// Client defined TODO
Client interface {
// Get returns *HttpRequest with GET method.
Get(url string) *client.HttpRequest
// Post returns *HttpRequest with POST method.
Post(url string) *client.HttpRequest
// Put returns *HttpRequest with PUT method.
Put(url string) *client.HttpRequest
// Delete returns *HttpRequest DELETE method.
Delete(url string) *client.HttpRequest
// Head returns *HttpRequest with HEAD method.
Head(url string) *client.HttpRequest
}

// ServiceContext defined TODO
ServiceContext struct {
Report Report
Store Store
Client Client
DB DB
}
)
// ServiceContext defined TODO
type ServiceContext struct {
Report svc.Report
Store svc.Store
Client svc.Client
DB svc.DB
}

// NewServiceContext defined TODO
func NewServiceContext(cache persistence.CacheStore) *ServiceContext {
Expand Down
12 changes: 12 additions & 0 deletions examples/aisle/types/about_us.auto.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions examples/aisle/types/aboutus_content_pic.auto.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions examples/aisle/types/achievement_send_email_msg.auto.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions examples/aisle/types/active_lesson.auto.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ffd2d98

Please sign in to comment.