-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
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...) | ||
} |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
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...) | ||
} |
This file was deleted.