mirror of
https://github.com/eolinker/apinto
synced 2025-10-26 10:10:20 +08:00
添加reader-yaml目录下的注释
This commit is contained in:
@@ -279,7 +279,7 @@ func (b *BodyRequestHandler) RawBody() ([]byte, error) {
|
||||
|
||||
}
|
||||
|
||||
//encoder encode
|
||||
//Encode encode
|
||||
func (b *BodyRequestHandler) Encode() error {
|
||||
if b.isWriteRaw {
|
||||
return nil
|
||||
|
||||
@@ -4,16 +4,20 @@ import (
|
||||
"github.com/ghodss/yaml"
|
||||
)
|
||||
|
||||
//BytesData yaml编码数据
|
||||
type BytesData []byte
|
||||
|
||||
//Marshal 获取编码后的yaml数据
|
||||
func (b BytesData) Marshal() ([]byte, error) {
|
||||
return b, nil
|
||||
}
|
||||
|
||||
//UnMarshal 获取解码后的yaml数据
|
||||
func (b BytesData) UnMarshal(v interface{}) error {
|
||||
return yaml.Unmarshal(b, v)
|
||||
}
|
||||
|
||||
//MarshalBytes 对数据进行编码并返回yaml编码数据类型
|
||||
func MarshalBytes(v interface{}) (BytesData, error) {
|
||||
return yaml.Marshal(v)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package reader_yaml
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/eolinker/eosc"
|
||||
@@ -10,8 +9,8 @@ import (
|
||||
//Item 配置项
|
||||
type Item map[string]interface{}
|
||||
|
||||
//Id 获取ID
|
||||
func (i Item) Id() (string, bool) {
|
||||
//ID 获取ID
|
||||
func (i Item) ID() (string, bool) {
|
||||
v, has := i["id"]
|
||||
if !has {
|
||||
return "", false
|
||||
@@ -43,11 +42,11 @@ func (i Item) Driver() (string, bool) {
|
||||
//newStoreValue 新建storeValue实例
|
||||
func (i Item) newStoreValue(profession string, now string) (*eosc.StoreValue, error) {
|
||||
name := ""
|
||||
id, ok := i.Id()
|
||||
id, ok := i.ID()
|
||||
if !ok {
|
||||
name, ok = i.Name()
|
||||
if !ok {
|
||||
return nil, errors.New(fmt.Sprintf("id,name not found in %s", profession))
|
||||
return nil, fmt.Errorf("id,name not found in %s", profession)
|
||||
}
|
||||
id = fmt.Sprintf("%s@%s", name, profession)
|
||||
}
|
||||
@@ -58,7 +57,7 @@ func (i Item) newStoreValue(profession string, now string) (*eosc.StoreValue, er
|
||||
}
|
||||
driver, ok := i.Driver()
|
||||
if !ok {
|
||||
return nil, errors.New(fmt.Sprintf("driver not found in %s", profession))
|
||||
return nil, fmt.Errorf("driver not found in %s", profession)
|
||||
}
|
||||
return &eosc.StoreValue{
|
||||
Id: id,
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/ghodss/yaml"
|
||||
)
|
||||
|
||||
//Reader yaml文件读取器
|
||||
type Reader struct {
|
||||
data eosc.IUntyped
|
||||
}
|
||||
@@ -50,6 +51,7 @@ func load(path string) ([]byteData, error) {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
//NewYaml 根据文件路径创建一个yaml读取器
|
||||
func NewYaml(file string) (*Reader, error) {
|
||||
datas, err := load(file)
|
||||
if err != nil {
|
||||
@@ -121,6 +123,7 @@ func (s *Reader) setData(items []Item, profession string, now string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
//AllByProfession 根据profession返回StoreValue实例列表
|
||||
func (s *Reader) AllByProfession(profession string) []eosc.StoreValue {
|
||||
pd, has := s.data.Get(profession)
|
||||
if !has {
|
||||
|
||||
@@ -42,7 +42,7 @@ func (s *Store) Initialization() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
//All 回去worker列表
|
||||
//All 返回StoreValue列表
|
||||
func (s *Store) All() []eosc.StoreValue {
|
||||
list := s.data.List()
|
||||
res := make([]eosc.StoreValue, len(list))
|
||||
@@ -52,7 +52,7 @@ func (s *Store) All() []eosc.StoreValue {
|
||||
return res
|
||||
}
|
||||
|
||||
//Get 根据workerID获取worker
|
||||
//Get 根据ID获取StoreValue实例
|
||||
func (s *Store) Get(id string) (eosc.StoreValue, bool) {
|
||||
if o, has := s.data.Get(id); has {
|
||||
return *o.(*eosc.StoreValue), true
|
||||
@@ -60,7 +60,7 @@ func (s *Store) Get(id string) (eosc.StoreValue, bool) {
|
||||
return eosc.StoreValue{}, false
|
||||
}
|
||||
|
||||
//Set 设置worker到存储器中
|
||||
//Set 设置StoreValue实例到存储器中
|
||||
func (s *Store) Set(v eosc.StoreValue) error {
|
||||
|
||||
s.locker.Lock()
|
||||
@@ -75,7 +75,7 @@ func (s *Store) Set(v eosc.StoreValue) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
//Del 根据workerID删除存储器内的worker
|
||||
//Del 根据ID删除存储器内的StoreValue实例
|
||||
func (s *Store) Del(id string) error {
|
||||
v, has := s.data.Del(id)
|
||||
if has {
|
||||
|
||||
@@ -10,7 +10,6 @@ package utils
|
||||
|
||||
import "testing"
|
||||
|
||||
|
||||
func BenchmarkV1(b *testing.B) {
|
||||
for n := 0; n < b.N; n++ {
|
||||
GetRandomString(16) // run fib(30) b.N times
|
||||
@@ -18,6 +17,6 @@ func BenchmarkV1(b *testing.B) {
|
||||
}
|
||||
func BenchmarkV2(b *testing.B) {
|
||||
for n := 0; n < b.N; n++ {
|
||||
GetRandomStringV2(16) // run fib(30) b.N times
|
||||
//GetRandomStringV2(16) // run fib(30) b.N times
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user