Skip to content

Commit

Permalink
Tiny tweaks for doc & code (#314)
Browse files Browse the repository at this point in the history
* [doc]: tweaks README.zh-CN.md fmt

* tweaks for code readable

* Fix typos & remove redundant code

* Fix wrong code change
  • Loading branch information
invzhi committed Oct 22, 2021
1 parent 6797c9a commit c6a3d76
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 31 deletions.
14 changes: 7 additions & 7 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
- **弹性和容错**。
- **断路器**: 暂时阻止可能的故障。
- **速率限制**: 限制请求的速率。
- **重试** :重试失败的请求。
- **重试**:重试失败的请求。
- **时间限制**:限制请求的执行时间。
- **部署管理**
- **蓝绿部署**:一次性切换流量。
Expand Down Expand Up @@ -127,7 +127,7 @@ Easegress 的基本用法是做为后端服务器的代理。下面分步说明

我们可以从[发布页](https://github.com/megaease/easegress/releases)下载 Easegress 的最新或历史版本。例如,可以使用下面的命令安装 v1.0.0 的 Linux:

``` bash
```bash
$ mkdir easegress
$ wget https://github.com/megaease/easegress/releases/download/v1.0.0/easegress-v1.0.0-linux-amd64.tar.gz
$ tar zxvf easegress-v1.0.0-linux-amd64.tar.gz -C easegress && cd easegress
Expand All @@ -142,7 +142,7 @@ $ make

然后把二进制所在目录添加到 `PATH` 中,并启动服务:

``` bash
```bash
$ export PATH=${PATH}:$(pwd)/bin/
$ easegress-server
2021-05-17T16:45:38.185+08:00 INFO cluster/config.go:84 etcd config: init-cluster:eg-default-name=http:https://localhost:2380 cluster-state:new force-new-cluster:false
Expand All @@ -160,9 +160,9 @@ $ easegress-server

Makefile 默认会将两个二进制文件编译到 `bin/` 目录中。`bin/easegress-server` 是服务器端的二进制文件,`bin/egctl` 是客户端的二进制文件。我们可以把它添加到 `$PATH` 中,以便于执行后续命令。

如果启动时不指定任何参数,`easegress-server` 会默认使用端口 2379、2380 和 2381。 我们可以在配置文件中更改默认端口,或者在命令行启动时指定相关参数(参数具体释义可通过执行 `easegress-server --help` 命令获取)。
如果启动时不指定任何参数,`easegress-server` 会默认使用端口 2379、2380 和 2381。我们可以在配置文件中更改默认端口,或者在命令行启动时指定相关参数(参数具体释义可通过执行 `easegress-server --help` 命令获取)。

``` bash
```bash
$ egctl member list
- options:
name: eg-default-name
Expand Down Expand Up @@ -216,7 +216,7 @@ rules:

上面的路由规则将把路径前缀为 `/pipeline` 的请求分发到名为 `pipeline-demo` 的 Pipeline,目前还没有这条 Pipeline,如果 `curl` 这个地址,将返回 503。

``` bash
```bash
$ echo '
name: pipeline-demo
kind: HTTPPipeline
Expand All @@ -240,7 +240,7 @@ filters:

现在可以使用一个 HTTP 客户端,如 `curl` 进行测试:

``` bash
```bash
$ curl -v http:https://127.0.0.1:10080/pipeline
```

Expand Down
16 changes: 8 additions & 8 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ import (
"sync"
"time"

"gopkg.in/yaml.v2"

"github.com/megaease/easegress/pkg/logger"
yaml "gopkg.in/yaml.v2"
)

func aboutText() string {
Expand All @@ -52,11 +53,11 @@ var (
appendAddonAPIs []func(s *Server, group *Group)
)

type apisbyOrder []*Group
type apisByOrder []*Group

func (a apisbyOrder) Less(i, j int) bool { return a[i].Group < a[j].Group }
func (a apisbyOrder) Len() int { return len(a) }
func (a apisbyOrder) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a apisByOrder) Less(i, j int) bool { return a[i].Group < a[j].Group }
func (a apisByOrder) Len() int { return len(a) }
func (a apisByOrder) Swap(i, j int) { a[i], a[j] = a[j], a[i] }

// RegisterAPIs registers global admin APIs.
func RegisterAPIs(apiGroup *Group) {
Expand Down Expand Up @@ -146,13 +147,12 @@ func (s *Server) listAPIs(w http.ResponseWriter, r *http.Request) {
apisMutex.Lock()
defer apisMutex.Unlock()

apiGroups := []*Group{}

apiGroups := make([]*Group, 0, len(apis))
for _, group := range apis {
apiGroups = append(apiGroups, group)
}

sort.Sort(apisbyOrder(apiGroups))
sort.Sort(apisByOrder(apiGroups))

buff, err := yaml.Marshal(apiGroups)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/dynamicmux.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"

"github.com/megaease/easegress/pkg/logger"
)

Expand Down Expand Up @@ -67,13 +68,12 @@ func (m *dynamicMux) reloadAPIs() {
apisMutex.Lock()
defer apisMutex.Unlock()

apiGroups := []*Group{}

apiGroups := make([]*Group, 0, len(apis))
for _, group := range apis {
apiGroups = append(apiGroups, group)
}

sort.Sort(apisbyOrder(apiGroups))
sort.Sort(apisByOrder(apiGroups))

router := chi.NewMux()
router.Use(middleware.StripSlashes)
Expand Down
2 changes: 1 addition & 1 deletion pkg/object/httpserver/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (r *runtime) reload(nextSuperSpec *supervisor.Spec, muxMapper protocol.MuxM

nextSpec := nextSuperSpec.ObjectSpec().(*Spec)

// r.limitListener does not created just after the process started and the config load for the first time.
// r.limitListener is not created just after the process started and the config load for the first time.
if nextSpec != nil && r.limitListener != nil {
r.limitListener.SetMaxConnection(nextSpec.MaxConnections)
}
Expand Down
25 changes: 14 additions & 11 deletions pkg/supervisor/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ import (
"sync"
"time"

"gopkg.in/yaml.v2"

"github.com/megaease/easegress/pkg/cluster"
"github.com/megaease/easegress/pkg/logger"
"github.com/megaease/easegress/pkg/protocol"
yaml "gopkg.in/yaml.v2"
)

type (
Expand Down Expand Up @@ -181,16 +182,18 @@ func (or *ObjectRegistry) run() {

func (or *ObjectRegistry) applyConfig(config map[string]string) {
or.mutex.Lock()
defer func() {
or.mutex.Unlock()
}()
defer or.mutex.Unlock()

del, create, update := make(map[string]*ObjectEntity), make(map[string]*ObjectEntity), make(map[string]*ObjectEntity)
var (
deleted = make(map[string]*ObjectEntity)
created = make(map[string]*ObjectEntity)
updated = make(map[string]*ObjectEntity)
)

for name, entity := range or.entities {
if _, exists := config[name]; !exists {
delete(or.entities, name)
del[name] = entity
deleted[name] = entity
}
}

Expand All @@ -207,9 +210,9 @@ func (or *ObjectRegistry) applyConfig(config map[string]string) {
}

if prevEntity != nil {
update[name] = entity
updated[name] = entity
} else {
create[name] = entity
created[name] = entity
}
or.entities[name] = entity
}
Expand All @@ -221,19 +224,19 @@ func (or *ObjectRegistry) applyConfig(config map[string]string) {

event := newObjectEntityWatcherEvent()

for name, entity := range del {
for name, entity := range deleted {
if watcher.filter(entity) {
event.Delete[name] = entity
delete(watcher.entities, name)
}
}
for name, entity := range create {
for name, entity := range created {
if watcher.filter(entity) {
event.Create[name] = entity
watcher.entities[name] = entity
}
}
for name, entity := range update {
for name, entity := range updated {
if watcher.filter(entity) {
event.Update[name] = entity
watcher.entities[name] = entity
Expand Down
2 changes: 1 addition & 1 deletion pkg/supervisor/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (s *Supervisor) NewSpec(yamlConfig string) (spec *Spec, err error) {

// Meta part.
meta := &MetaSpec{}
yamltool.Unmarshal([]byte(yamlBuff), meta)
yamltool.Unmarshal(yamlBuff, meta)
verr := v.Validate(meta)
if !verr.Valid() {
panic(verr)
Expand Down

0 comments on commit c6a3d76

Please sign in to comment.