Skip to content

Commit

Permalink
http call
Browse files Browse the repository at this point in the history
  • Loading branch information
iesreza committed Feb 17, 2022
1 parent 68cc6f7 commit 2b99b26
Show file tree
Hide file tree
Showing 10 changed files with 1,085 additions and 194 deletions.
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
- Event: onBeforeWrite
- Cache Middleware
- Redis: Universal client
8 changes: 5 additions & 3 deletions cmd/evo/ng/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ var ContextInterface = Function{
}

func Start() {
err := os.Remove("./go.mod")
if err != nil {
evo.Panic(err)
if !file.IsFileExist("./app.json") {
panic("missing app.json")
}
os.Remove("./go.mod")
skeleton = GetSkeleton("./app.json")

main.Events.Set("OverRide", generator.NewFunc(nil, generator.NewFuncSignature("OverRide")))
Expand Down Expand Up @@ -148,6 +148,8 @@ func run(cmd string, args ...string) {
fmt.Println(cmd, strings.Join(args, " "))
c := exec.Command(cmd, args...)
c.Dir = file.WorkingDir()
c.Stdout = os.Stdout
c.Stderr = os.Stderr
err := c.Run()
if err != nil {
evo.Panic(err)
Expand Down
86 changes: 56 additions & 30 deletions cmd/evo/ng/skeleton.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,45 +67,71 @@ func (s *Skeleton) GenContext() {
context,
)

var commonStatements = append(statements, generator.NewReturnStatement("callback.(func(*Context) error)(c)"))
var wsStatements = append(statements, generator.NewReturnStatement("callback.(func(*Context,*websocket.Conn) error)(c,ws)"))

root = root.AddStatements(generator.NewNewline(),
generator.NewCommentf("New create new type of struct"),
generator.NewFunc(
generator.NewFuncReceiver("c", "*Context"),
generator.NewFuncSignature("New").AddReturnTypes("evo.ContextInterface"),
generator.NewReturnStatement("&Context{}"),
))
for _, method := range []string{"Get", "Post", "All", "Put", "Patch", "Options", "Connect", "Head", "Delete", "Use", "WebSocket"} {
if method == "WebSocket" {
root = root.AddStatements(
generator.NewNewline(),
generator.NewCommentf("%s Wrap context http %s requests. callback accepts func(*http.Context,*websocket.Conn)", method, method),
generator.NewFunc(
generator.NewFuncReceiver("c", "*Context"),
generator.NewFuncSignature(method).AddParameters(
generator.NewFuncParameter("request ", "*evo.Context"),
generator.NewFuncParameter("callback", "interface{}"),
generator.NewFuncParameter("ws", "*websocket.Conn"),
).AddReturnTypes("err error"),
wsStatements...,
),

generator.NewNewline(),
generator.NewCommentf("%s Matches http %s requests. callback accepts func(*http.Context)", method, method),
generator.NewFunc(
nil,
generator.NewFuncSignature(method).AddParameters(
generator.NewFuncParameter("url ", "string"),
generator.NewFuncParameter("callback", "func(*Context,*websocket.Conn) error"),
generator.NewFuncParameter("params...", "interface{}"),
root = root.AddStatements(
generator.NewNewline(),
generator.NewCommentf("%s Wrap context ws/wss %s requests. callback accepts func(*http.Context,*websocket.Conn)", "WebSocket", "WebSocket"),
generator.NewFunc(
generator.NewFuncReceiver("c", "*Context"),
generator.NewFuncSignature("WebSocket").AddParameters(
generator.NewFuncParameter("request ", "*evo.Context"),
generator.NewFuncParameter("callback", "interface{}"),
generator.NewFuncParameter("ws", "*websocket.Conn"),
).AddReturnTypes("err error"),
append(statements, generator.NewReturnStatement("callback.(func(*Context,*websocket.Conn) error)(c,ws)"))...,
),

generator.NewNewline(),
generator.NewCommentf("%s Matches http %s requests. callback accepts func(*http.Context)", "WebSocket", "WebSocket"),
generator.NewFunc(
nil,
generator.NewFuncSignature("WebSocket").AddParameters(
generator.NewFuncParameter("url ", "string"),
generator.NewFuncParameter("callback", "func(*Context,*websocket.Conn) error"),
generator.NewFuncParameter("params...", "interface{}"),
),
generator.NewRawStatement("evo."+"WebSocket"+("(url,callback,params...)")),
),
)
var commonStatements = append(statements, generator.NewReturnStatement("callback.(func(*Context) error)(c)"))
for _, method := range []string{"Get", "Post", "All", "Put", "Patch", "Options", "Connect", "Head", "Delete", "Use"} {
/* if method == "WebSocket" {
var wsStatements = append(statements, generator.NewReturnStatement("callback.(func(*Context,*websocket.Conn) error)(c,ws)"))
root = root.AddStatements(
generator.NewNewline(),
generator.NewCommentf("%s Wrap context ws/wss %s requests. callback accepts func(*http.Context,*websocket.Conn)", method, method),
generator.NewFunc(
generator.NewFuncReceiver("c", "*Context"),
generator.NewFuncSignature(method).AddParameters(
generator.NewFuncParameter("request ", "*evo.Context"),
generator.NewFuncParameter("callback", "interface{}"),
generator.NewFuncParameter("ws", "*websocket.Conn"),
).AddReturnTypes("err error"),
wsStatements...,
),
generator.NewRawStatement("evo."+method+("(url,callback,params...)")),
),
)
continue
}
generator.NewNewline(),
generator.NewCommentf("%s Matches http %s requests. callback accepts func(*http.Context)", method, method),
generator.NewFunc(
nil,
generator.NewFuncSignature(method).AddParameters(
generator.NewFuncParameter("url ", "string"),
generator.NewFuncParameter("callback", "func(*Context,*websocket.Conn) error"),
generator.NewFuncParameter("params...", "interface{}"),
),
generator.NewRawStatement("evo."+method+("(url,callback,params...)")),
),
)
continue
}*/

root = root.AddStatements(
generator.NewNewline(),
generator.NewCommentf("%s Wrap context http %s requests. callback accepts func(*http.Context)", method, method),
Expand Down
31 changes: 14 additions & 17 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@ package evo
import (
"context"
"fmt"
"github.com/coreos/etcd/clientv3"
"github.com/creasty/defaults"
"github.com/getevo/evo-ng/lib/args"
consul_api "github.com/hashicorp/consul/api"
vault_api "github.com/hashicorp/vault/api"
"github.com/heetch/confita"
"github.com/heetch/confita/backend/consul"
"github.com/heetch/confita/backend/env"
"github.com/heetch/confita/backend/etcd"
"github.com/heetch/confita/backend/file"
"github.com/heetch/confita/backend/flags"
"github.com/heetch/confita/backend/vault"
"reflect"
"strings"
"time"
)

Expand Down Expand Up @@ -145,22 +142,22 @@ func ParseConfig(params ...interface{}) error {
)
} else if args.Get("-etcd") != "" {
fmt.Println("Load config from etcd")
client, err := clientv3.New(clientv3.Config{
Username: args.Get("-etcd-username"),
Password: args.Get("-etcd-password"),
Endpoints: strings.Split(args.Get("-etcd"), ","),
})
if err == nil {
return err
}
/* client, err := clientv3.New(clientv3.Config{
Username: args.Get("-etcd-username"),
Password: args.Get("-etcd-password"),
Endpoints: strings.Split(args.Get("-etcd"), ","),
})
if err == nil {
return err
}
loader = confita.NewLoader(
etcd.NewBackend(client, etcd.WithPrefix("-etcd-prefix")),
)
loader = confita.NewLoader(
etcd.NewBackend(client, etcd.WithPrefix("-etcd-prefix")),
)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
loader.Load(ctx, params[out])
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
loader.Load(ctx, params[out])*/

} else if args.Get("-vault") != "" {
var cfg = vault_api.DefaultConfig()
Expand Down
82 changes: 16 additions & 66 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,91 +1,41 @@
module github.com/getevo/evo-ng

go 1.17
go 1.16

require (
github.com/CloudyKit/jet/v6 v6.1.0
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de
github.com/awoodbeck/strftime v0.0.0-20180221155908-016cde65fcde
github.com/creasty/defaults v1.5.2
github.com/fasthttp/websocket v1.4.4
github.com/fasthttp/websocket v1.4.6
github.com/fatih/color v1.13.0
github.com/getevo/evo v1.0.6
github.com/getevo/evo v1.0.9
github.com/getevo/monday v1.0.2
github.com/go-git/go-git/v5 v5.4.2
github.com/go-redis/redis/v8 v8.11.4
github.com/go-redis/redis_rate/v9 v9.1.2
github.com/gofiber/fiber/v2 v2.24.0
github.com/gofiber/fiber/v2 v2.27.0
github.com/hart87/GoFlake v0.0.0-20210517135841-c95a47da3eb9
github.com/hart87/goflake v0.0.0-20210517135841-c95a47da3eb9 // indirect
github.com/hashicorp/consul/api v1.12.0
github.com/hashicorp/vault/api v1.3.1
github.com/heetch/confita v0.10.0
github.com/kelindar/binary v1.0.17
github.com/mattn/go-zglob v0.0.3
github.com/mitchellh/mapstructure v1.4.1 // indirect
github.com/moznion/gowrtr v1.5.1
github.com/otiai10/copy v1.7.0
github.com/pkg/errors v0.9.1
github.com/tidwall/gjson v1.12.1
github.com/stretchr/testify v1.7.0
github.com/tidwall/gjson v1.14.0
github.com/tidwall/sjson v1.2.4
github.com/valyala/fasthttp v1.31.0
golang.org/x/mod v0.3.0
github.com/valyala/fasthttp v1.33.0
golang.org/x/mod v0.5.1
golang.org/x/text v0.3.7
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
gorm.io/driver/mysql v1.0.4
gorm.io/driver/mysql v1.2.3
gorm.io/driver/postgres v1.2.3
gorm.io/driver/sqlite v1.1.4
gorm.io/driver/sqlserver v1.0.6
gorm.io/gorm v1.22.3
gorm.io/driver/sqlite v1.2.6
gorm.io/driver/sqlserver v1.2.1
gorm.io/gorm v1.22.5
gorm.io/plugin/dbresolver v1.1.0
)

require (
github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53 // indirect
github.com/CloudyKit/jet v2.1.2+incompatible // indirect
github.com/Microsoft/go-winio v0.4.16 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect
github.com/acomagu/bufpipe v1.0.3 // indirect
github.com/andybalholm/brotli v1.0.2 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/emirpasic/gods v1.12.0 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-git/go-billy/v5 v5.3.1 // indirect
github.com/go-sql-driver/mysql v1.5.0 // indirect
github.com/gofiber/websocket/v2 v2.0.15 // indirect
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe // indirect
github.com/hart87/goflake v0.0.0-20210517135841-c95a47da3eb9 // indirect
github.com/heetch/confita v0.10.0
github.com/imdario/mergo v0.3.12 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.10.1 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.2.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
github.com/jackc/pgtype v1.9.0 // indirect
github.com/jackc/pgx/v4 v4.14.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/jinzhu/copier v0.3.4 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.2 // indirect
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
github.com/klauspost/compress v1.13.4 // indirect
github.com/mattn/go-colorable v0.1.9 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-sqlite3 v1.14.5 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/savsgio/gotils v0.0.0-20211223103454-d0aaa54c5899 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/stretchr/testify v1.7.0
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
github.com/wzshiming/ctc v1.2.3 // indirect
github.com/wzshiming/winseq v0.0.0-20200112104235-db357dc107ae // indirect
github.com/xanzy/ssh-agent v0.3.0 // indirect
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
golang.org/x/net v0.0.0-20210510120150-4163338589ed // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
)
Loading

0 comments on commit 2b99b26

Please sign in to comment.