Skip to content

Commit

Permalink
pubsub and memo
Browse files Browse the repository at this point in the history
  • Loading branch information
iesreza committed Nov 30, 2023
1 parent ef44274 commit 60955e2
Show file tree
Hide file tree
Showing 68 changed files with 1,093 additions and 752 deletions.
18 changes: 9 additions & 9 deletions errors/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ package e
import "fmt"

type Error struct {
Type string `json:"type"`
Field string `json:"field,omitempty"`
Message string `json:"message"`
Solution string `json:"solution,omitempty"`
Params *[]interface{} `json:"params,omitempty"`
Type string `json:"type"`
Field string `json:"field,omitempty"`
Message string `json:"message"`
Solution string `json:"solution,omitempty"`
Params *[]any `json:"params,omitempty"`
}

type Errors []Error

func New(t, field, message, solution string, params ...interface{}) *Error {
func New(t, field, message, solution string, params ...any) *Error {
return &Error{
t, field, message, solution, &params,
}
}

func Field(field, message interface{}, params ...interface{}) *Error {
func Field(field, message any, params ...any) *Error {
return New("field", fmt.Sprint(field), fmt.Sprint(message), "", params)
}

func Context(message interface{}, params ...interface{}) *Error {
func Context(message any, params ...any) *Error {
return New("context", "", fmt.Sprint(message), "", params)
}

Expand All @@ -31,7 +31,7 @@ func (e *Error) SetSolution(s string) *Error {
return e
}

func (e *Error) SetParams(params ...interface{}) *Error {
func (e *Error) SetParams(params ...any) *Error {
e.Params = &params
return e
}
Expand Down
16 changes: 8 additions & 8 deletions evo.context.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ type Request struct {
}

type Response struct {
Success bool `json:"success"`
Error []string `json:"errors,omitempty"`
Data interface{} `json:"data,omitempty"`
Success bool `json:"success"`
Error []string `json:"errors,omitempty"`
Data any `json:"data,omitempty"`
}

type URL struct {
Expand Down Expand Up @@ -72,7 +72,7 @@ func (r *Request) URL() *URL {
}
return r.url
}
func (u *URL) Set(key string, value interface{}) *URL {
func (u *URL) Set(key string, value any) *URL {
u.Query.Set(key, fmt.Sprint(value))
return u
}
Expand All @@ -87,7 +87,7 @@ func Upgrade(ctx *fiber.Ctx) *Request {
return &r
}

func (r *Request) WriteResponse(resp ...interface{}) {
func (r *Request) WriteResponse(resp ...any) {

if len(resp) == 0 {
return
Expand Down Expand Up @@ -215,7 +215,7 @@ func (r *Request) _writeResponse(resp Response) {

}

func (r *Request) Error(err interface{}, code ...int) bool {
func (r *Request) Error(err any, code ...int) bool {
if err == nil {
return false
}
Expand All @@ -234,7 +234,7 @@ func (r *Request) Error(err interface{}, code ...int) bool {
return true
}

func (r *Request) PushError(err interface{}, code ...int) bool {
func (r *Request) PushError(err any, code ...int) bool {
if err == nil {
return false
}
Expand All @@ -256,7 +256,7 @@ func (r *Request) HasError() bool {
return len(r.Response.Error) > 0
}

func (r *Request) Var(key string, value ...interface{}) generic.Value {
func (r *Request) Var(key string, value ...any) generic.Value {
return generic.Parse(r.Context.Locals(key, value...))
}

Expand Down
4 changes: 2 additions & 2 deletions evo.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package evo

import (
"github.com/getevo/evo/v2/lib/cache"
dbo "github.com/getevo/evo/v2/lib/db"
"github.com/getevo/evo/v2/lib/generic"
"github.com/getevo/evo/v2/lib/memo"
"github.com/getevo/evo/v2/lib/settings"
"github.com/getevo/evo/v2/lib/settings/database"
"github.com/gofiber/fiber/v2"
Expand Down Expand Up @@ -35,7 +35,7 @@ func Setup() {
settings.SetDefaultDriver(database.Driver)
}

cache.Register()
memo.Register()

}

Expand Down
2 changes: 1 addition & 1 deletion evo.user.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func (r *Request) User() *UserInterface {

type DefaultUserInterface struct{}

type Attributes map[string]interface{}
type Attributes map[string]any

func (d DefaultUserInterface) Attributes() Attributes {
return Attributes{}
Expand Down
18 changes: 13 additions & 5 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@ package main
import (
"fmt"
"github.com/getevo/evo/v2"
"github.com/getevo/evo/v2/lib/connectors/nats"
"github.com/getevo/evo/v2/lib/connectors/redis"
"github.com/getevo/evo/v2/lib/memo"
"github.com/getevo/evo/v2/lib/pubsub"
"github.com/getevo/evo/v2/lib/settings"
)

func main() {
evo.Setup()
fmt.Println(settings.Get("NATS.SERVER").String())

pubsub.AddDriver(redis.Driver)
memo.SetDefaultDriver(nats.Driver)

//var db = evo.GetDBO()
/* var data = map[string]interface{}{}
/* var data = map[string]any{}
db.Raw("SELECT * FROM services").Scan(&data)
cache.SetDefaultDriver(redis.Driver)
Expand All @@ -32,12 +40,12 @@ func main() {
log.SetLevel(log.DebugLevel)*/

var group = evo.Group("/group").Name("mygroup")
group.Get("/:id", func(request *evo.Request) interface{} {
group.Get("/:id", func(request *evo.Request) any {
var r = request.Route("mygroup.gregory", 125)
return r
}).Name("gregory")

evo.Get("/struct", func(request *evo.Request) interface{} {
evo.Get("/struct", func(request *evo.Request) any {
return struct {
Text string `json:"text"`
Integer int `json:"integer"`
Expand All @@ -46,11 +54,11 @@ func main() {
}
})

evo.Get("/bytes", func(request *evo.Request) interface{} {
evo.Get("/bytes", func(request *evo.Request) any {
return []byte{'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd'}
})

evo.Get("/outcome", func(request *evo.Request) interface{} {
evo.Get("/outcome", func(request *evo.Request) any {
return []error{fmt.Errorf("my error 1"), fmt.Errorf("my error 2")}
})
evo.Run()
Expand Down
22 changes: 11 additions & 11 deletions fiber.context.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (r *Request) Body() string {
// BodyParser binds the request body to a struct.
// It supports decoding the following content types based on the Content-Type header:
// application/json, application/xml, application/x-www-form-urlencoded, multipart/form-data
func (r *Request) BodyParser(out interface{}) error {
func (r *Request) BodyParser(out any) error {
ctype := r.ContentType()

if strings.HasPrefix(ctype, MIMEApplicationJSON) {
Expand Down Expand Up @@ -164,7 +164,7 @@ func (r *Request) Download(file string, name ...string) error {
// Format performs content-negotiation on the Accept HTTP header.
// It uses Accepts to select a proper format.
// If the header is not specified or there is no proper format, text/plain is used.
func (r *Request) Format(body interface{}) error {
func (r *Request) Format(body any) error {
var b string
accept := r.Context.Accepts("html", "json")

Expand Down Expand Up @@ -350,7 +350,7 @@ func (r *Request) Is(extension string) (match bool) {

// JSON converts any interface or string to JSON using Jsoniter.
// This method also sets the content header to application/json.
func (r *Request) JSON(data interface{}) error {
func (r *Request) JSON(data any) error {
raw, err := json.Marshal(data)
// Check for errors
if err != nil {
Expand All @@ -366,7 +366,7 @@ func (r *Request) JSON(data interface{}) error {
// JSONP sends a JSON response with JSONP support.
// This method is identical to JSON, except that it opts-in to JSONP callback support.
// By default, the callback name is simply callback.
func (r *Request) JSONP(json interface{}, callback ...string) error {
func (r *Request) JSONP(json any, callback ...string) error {
return r.Context.JSONP(json, callback...)
}

Expand All @@ -375,9 +375,9 @@ func (r *Request) Links(link ...string) {
r.Context.Links(link...)
}

// Locals makes it possible to pass interface{} values under string keys scoped to the request
// Locals makes it possible to pass any values under string keys scoped to the request
// and therefore available to all following routes that match the request.
func (r *Request) Locals(key string, value ...interface{}) (val interface{}) {
func (r *Request) Locals(key string, value ...any) (val any) {
return r.Context.Locals(key, value...)
}

Expand Down Expand Up @@ -447,7 +447,7 @@ func (r *Request) IsSecure() bool {
}

// Send sets the HTML response body. The Send body can be of any type.
func (r *Request) SendHTML(body interface{}) {
func (r *Request) SendHTML(body any) {
r.Set("Content-Type", "text/html")
r.Write(body)
}
Expand Down Expand Up @@ -518,7 +518,7 @@ func (r *Request) Vary(fields ...string) {
}

// Write appends any input to the HTTP body response.
func (r *Request) Write(body interface{}) {
func (r *Request) Write(body any) {
var data []byte
switch body := body.(type) {
case string:
Expand Down Expand Up @@ -548,7 +548,7 @@ func (r *Request) XHR() bool {
}

// SetCookie set cookie with given name,value and optional params (wise function)
func (r *Request) SetCookie(key string, val interface{}, params ...interface{}) {
func (r *Request) SetCookie(key string, val any, params ...any) {
cookie := new(outcome.Cookie)
cookie.Name = key
cookie.Path = "/"
Expand Down Expand Up @@ -585,7 +585,7 @@ func (r *Request) Params() map[string]string {
}

// Route generate route for named routes
func (r *Request) Route(name string, params ...interface{}) string {
func (r *Request) Route(name string, params ...any) string {
var m = fiber.Map{}
var jump = false
var route = app.GetRoute(name)
Expand All @@ -605,7 +605,7 @@ func (r *Request) Route(name string, params ...interface{}) string {
m[p] = params[idx+1]
jump = true
}
case map[string]interface{}:
case map[string]any:
m = p
}
}
Expand Down
2 changes: 1 addition & 1 deletion fiber.evo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/gofiber/fiber/v2"
)

type Handler func(request *Request) interface{}
type Handler func(request *Request) any
type Middleware func(request *Request) error

type group struct {
Expand Down
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ require (
github.com/iancoleman/strcase v0.2.0
github.com/jlaffaye/ftp v0.1.0
github.com/kelindar/binary v1.0.17
github.com/nats-io/nats.go v1.29.0
github.com/nats-io/nats.go v1.31.0
github.com/otiai10/copy v1.9.0
github.com/pkg/sftp v1.13.5
github.com/segmentio/kafka-go v0.4.39
github.com/stretchr/testify v1.8.2
github.com/tidwall/gjson v1.7.4
github.com/valyala/fasthttp v1.50.0
go.uber.org/multierr v1.9.0
golang.org/x/crypto v0.12.0
golang.org/x/text v0.12.0
golang.org/x/crypto v0.16.0
golang.org/x/text v0.14.0
gopkg.in/yaml.v3 v3.0.1
gorm.io/driver/mysql v1.4.7
gorm.io/driver/sqlite v1.4.4
Expand Down Expand Up @@ -58,7 +58,7 @@ require (
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/klauspost/compress v1.17.3 // indirect
github.com/kr/fs v0.1.0 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand All @@ -67,10 +67,10 @@ require (
github.com/mattn/go-sqlite3 v1.14.15 // indirect
github.com/microsoft/go-mssqldb v0.19.0 // indirect
github.com/nats-io/nats-server/v2 v2.9.22 // indirect
github.com/nats-io/nkeys v0.4.4 // indirect
github.com/nats-io/nkeys v0.4.6 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/philhofer/fwd v1.1.2 // indirect
github.com/pierrec/lz4/v4 v4.1.15 // indirect
github.com/pierrec/lz4/v4 v4.1.18 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
Expand All @@ -82,7 +82,7 @@ require (
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/sys v0.15.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)
15 changes: 15 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ github.com/kelindar/binary v1.0.17/go.mod h1:/twdz8gRLNMffx0U4UOgqm1LywPs6nd9YK2
github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I=
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/klauspost/compress v1.17.3 h1:qkRjuerhUU1EmXLYGkSH6EZL+vPSxIrYjLNAK4slzwA=
github.com/klauspost/compress v1.17.3/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand Down Expand Up @@ -151,8 +153,12 @@ github.com/nats-io/nats-server/v2 v2.9.22 h1:rzl88pqWFFrU4G00ed+JnY+uGHSLZ+3jrxD
github.com/nats-io/nats-server/v2 v2.9.22/go.mod h1:wEjrEy9vnqIGE4Pqz4/c75v9Pmaq7My2IgFmnykc4C0=
github.com/nats-io/nats.go v1.29.0 h1:dSXZ+SZeGyTdHVYeXimeq12FsIpb9dM8CJ2IZFiHcyE=
github.com/nats-io/nats.go v1.29.0/go.mod h1:XpbWUlOElGwTYbMR7imivs7jJj9GtK7ypv321Wp6pjc=
github.com/nats-io/nats.go v1.31.0 h1:/WFBHEc/dOKBF6qf1TZhrdEfTmOZ5JzdJ+Y3m6Y/p7E=
github.com/nats-io/nats.go v1.31.0/go.mod h1:di3Bm5MLsoB4Bx61CBTsxuarI36WbhAwOm8QrW39+i8=
github.com/nats-io/nkeys v0.4.4 h1:xvBJ8d69TznjcQl9t6//Q5xXuVhyYiSos6RPtvQNTwA=
github.com/nats-io/nkeys v0.4.4/go.mod h1:XUkxdLPTufzlihbamfzQ7mw/VGx6ObUs+0bN5sNvt64=
github.com/nats-io/nkeys v0.4.6 h1:IzVe95ru2CT6ta874rt9saQRkWfe2nFj1NtvYSLqMzY=
github.com/nats-io/nkeys v0.4.6/go.mod h1:4DxZNzenSVd1cYQoAa8948QY3QDjrHfcfVADymtkpts=
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
Expand All @@ -170,6 +176,8 @@ github.com/philhofer/fwd v1.1.1/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG
github.com/philhofer/fwd v1.1.2/go.mod h1:qkPdfjR2SIEbspLqpe1tO4n5yICnr2DY7mqEx2tUTP0=
github.com/pierrec/lz4/v4 v4.1.15 h1:MO0/ucJhngq7299dKLwIMtgTfbkoSPF6AoMYDd8Q4q0=
github.com/pierrec/lz4/v4 v4.1.15/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
github.com/pierrec/lz4/v4 v4.1.18 h1:xaKrnTkyoqfh1YItXl56+6KJNVYWlEEPuAQW9xsplYQ=
github.com/pierrec/lz4/v4 v4.1.18/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4/go.mod h1:N6UoU20jOqggOuDwUaBQpluzLNDqif3kq9z2wpdYEfQ=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
github.com/pkg/sftp v1.13.5 h1:a3RLUqkyjYRtBTZJZ1VRrKbN3zhuPLlUc3sphVz81go=
Expand Down Expand Up @@ -239,6 +247,8 @@ golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0
golang.org/x/crypto v0.0.0-20221005025214-4161e89ecf1b/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY=
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
Expand Down Expand Up @@ -281,17 +291,22 @@ golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA=
golang.org/x/term v0.11.0 h1:F9tnn/DA/Im8nCwm+fX+1/eBwi4qFjRT++MhtVC4ZX0=
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
Expand Down
Loading

0 comments on commit 60955e2

Please sign in to comment.