Skip to content

Commit

Permalink
[*] migrate to gou v0.10.3 (50%)
Browse files Browse the repository at this point in the history
  • Loading branch information
trheyi committed Feb 1, 2023
1 parent 8d40c8e commit a807899
Show file tree
Hide file tree
Showing 224 changed files with 1,648 additions and 6,624 deletions.
59 changes: 8 additions & 51 deletions api/api.go
Original file line number Diff line number Diff line change
@@ -1,60 +1,17 @@
package api

import (
"fmt"
"path/filepath"
"strings"

"github.com/yaoapp/gou"
"github.com/yaoapp/kun/log"
"github.com/yaoapp/gou/api"
"github.com/yaoapp/gou/application"
"github.com/yaoapp/yao/config"
"github.com/yaoapp/yao/share"
)

// Load 加载API
// Load apis
func Load(cfg config.Config) error {
if share.BUILDIN {
return LoadBuildIn("apis", "")
}
return LoadFrom(filepath.Join(cfg.Root, "apis"), "")
}

// LoadFrom 从特定目录加载
func LoadFrom(dir string, prefix string) error {
if share.DirNotExists(dir) {
return fmt.Errorf("%s does not exists", dir)
}

messages := []string{}
err := share.Walk(dir, ".http.json", func(root, filename string) {
name := prefix + share.SpecName(root, filename)
content := share.ReadFile(filename)
_, err := gou.LoadAPIReturn(string(content), name, "bearer-jwt")
if err != nil {
log.With(log.F{"root": root, "file": filename}).Error(err.Error())
messages = append(messages, fmt.Sprintf("%s %s", name, err.Error()))
}
})

// Load WebSocket Server
err = share.Walk(dir, ".ws.json", func(root, filename string) {
name := prefix + share.SpecName(root, filename)
content := share.ReadFile(filename)
_, err := gou.LoadWebSocketServer(string(content), name)
if err != nil {
log.With(log.F{"root": root, "file": filename}).Error(err.Error())
messages = append(messages, fmt.Sprintf("%s %s", name, err.Error()))
}
})

if len(messages) > 0 {
return fmt.Errorf("%s", strings.Join(messages, ";"))
}

return err
}

// LoadBuildIn 从制品中读取
func LoadBuildIn(dir string, prefix string) error {
return nil
exts := []string{"*.http.yao", "*.http.json", "*.http.jsonc"}
return application.App.Walk("apis", func(root, file string, isdir bool) error {
_, err := api.Load(file, share.ID(root, file))
return err
}, exts...)
}
6 changes: 2 additions & 4 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/yaoapp/gou"
"github.com/yaoapp/gou/api"
"github.com/yaoapp/gou/websocket"
"github.com/yaoapp/yao/config"
)

func TestLoad(t *testing.T) {
gou.APIs = make(map[string]*gou.API)
Load(config.Conf)
LoadFrom("not a path", "404.")
check(t)
}

func check(t *testing.T) {
keys := []string{}
for key := range gou.APIs {
for key := range api.APIs {
keys = append(keys, key)
}

Expand Down
1 change: 0 additions & 1 deletion app/README.md

This file was deleted.

82 changes: 0 additions & 82 deletions app/app.go

This file was deleted.

15 changes: 0 additions & 15 deletions app/app_test.go

This file was deleted.

8 changes: 0 additions & 8 deletions brain/README.md

This file was deleted.

1 change: 0 additions & 1 deletion brain/behaviors/listen/listen.go

This file was deleted.

1 change: 0 additions & 1 deletion brain/behaviors/send/send.go

This file was deleted.

7 changes: 0 additions & 7 deletions brain/behaviors/zouyu/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions brain/behaviors/zouyu/types.go

This file was deleted.

14 changes: 0 additions & 14 deletions brain/behaviors/zouyu/zouyu.go

This file was deleted.

18 changes: 0 additions & 18 deletions brain/brain.go

This file was deleted.

11 changes: 0 additions & 11 deletions brain/brain_test.go

This file was deleted.

1 change: 0 additions & 1 deletion brain/cli/README.md

This file was deleted.

1 change: 0 additions & 1 deletion brain/cli/cli.go

This file was deleted.

3 changes: 0 additions & 3 deletions brain/cloud/README.md

This file was deleted.

9 changes: 0 additions & 9 deletions brain/types.go

This file was deleted.

1 change: 0 additions & 1 deletion brain/web/README.md

This file was deleted.

30 changes: 6 additions & 24 deletions cert/cert.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,17 @@
package cert

import (
"fmt"
"path/filepath"

"github.com/yaoapp/gou/application"
"github.com/yaoapp/gou/ssl"
"github.com/yaoapp/kun/log"
"github.com/yaoapp/yao/config"
"github.com/yaoapp/yao/share"
)

// Load 加载API
func Load(cfg config.Config) error {
var root = filepath.Join(cfg.Root, "certs")
return LoadFrom(root, "")
}

// LoadFrom 从特定目录加载
func LoadFrom(dir string, prefix string) error {

if share.DirNotExists(dir) {
return fmt.Errorf("%s does not exists", dir)
}

err := share.Walk(dir, ".pem", func(root, filename string) {
name := prefix + share.SpecName(root, filename)
_, err := ssl.LoadCertificateFrom(filename, name)
if err != nil {
log.With(log.F{"root": root, "file": filename}).Error(err.Error())
}
})

return err
exts := []string{"*.pem", "*.key", "*.pub"}
return application.App.Walk("certs", func(root, file string, isdir bool) error {
_, err := ssl.Load(file, share.ID(root, file))
return err
}, exts...)
}
7 changes: 3 additions & 4 deletions cert/cert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/yaoapp/gou"
"github.com/yaoapp/gou/process"
"github.com/yaoapp/gou/ssl"
"github.com/yaoapp/yao/config"
)

func TestLoad(t *testing.T) {
Load(config.Conf)
LoadFrom("not a path", "404.")
check(t)
}

func TestProcessSign(t *testing.T) {
Load(config.Conf)
args := []interface{}{"hello world", "private", "SHA256"}
signature, err := gou.NewProcess("ssl.Sign", args...).Exec()
signature, err := process.New("ssl.Sign", args...).Exec()
if err != nil {
t.Fatal(err)
}
Expand All @@ -29,7 +28,7 @@ func TestProcessVerify(t *testing.T) {
Load(config.Conf)
signature := "EDHf3C9TXEk7y8LzIk5czLefXZyGxcMDVMcbNuBBegDkTqnPsRQnhFtNOgCdox8lI3MzLatwjoljoMY4Qk+sHGd5mAHMpiREa1gRFSVYpA2xvXZ3+KsfOHAdICQrfUdy59QaJGo6iGPNGG8PQOXHPTVNn6LMfryat9+f4l21DPAZiT0RyCUgFZE3/Qv8Z/6J4AsIXMSKZD6BGPPHUxGe7UBrXZvcR5dX25EiNjuH2OO38YJnDiTRVw14UI5fk/mQrwRdezj5tSKFCyHt912BZExXtkHISiYFNTZ/2RhOup5Xx6o3GvrEOdshrnN80Lwu1Aaju+lnZp13hDz4P6hU7w=="
args := []interface{}{"hello world", signature, "cert", "SHA256"}
res, err := gou.NewProcess("ssl.Verify", args...).Exec()
res, err := process.New("ssl.Verify", args...).Exec()
if err != nil {
t.Fatal(err)
}
Expand Down
1 change: 0 additions & 1 deletion chart/REAME.md

This file was deleted.

Loading

0 comments on commit a807899

Please sign in to comment.