Skip to content

Commit e81b504

Browse files
committed
修复设置worker时,ID为空的问题
1 parent a07ac4e commit e81b504

File tree

5 files changed

+57
-12
lines changed

5 files changed

+57
-12
lines changed

config/config.go

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ package config
22

33
import (
44
"fmt"
5-
"github.com/eolinker/eosc/env"
6-
"github.com/eolinker/eosc/log"
7-
"github.com/ghodss/yaml"
85
"net"
96
"net/url"
107
"os"
118
"strconv"
129
"strings"
10+
11+
"github.com/eolinker/eosc/env"
12+
"github.com/eolinker/eosc/log"
13+
"github.com/ghodss/yaml"
1314
)
1415

1516
const (
@@ -197,13 +198,52 @@ func initial(c *NConfig) {
197198
}
198199
}
199200
c.Peer.AdvertiseUrls = parseHostName(c.Peer.AdvertiseUrls)
201+
200202
if len(c.Client.AdvertiseUrls) == 0 {
201203
c.Client.AdvertiseUrls = createAdvertiseUrls(c.Client.ListenUrls)
204+
202205
}
203206
c.Client.AdvertiseUrls = parseHostName(c.Client.AdvertiseUrls)
207+
204208
if len(c.Gateway.AdvertiseUrls) == 0 {
205209
c.Gateway.AdvertiseUrls = createAdvertiseUrls(c.Gateway.ListenUrls)
206-
}
207210

211+
}
208212
c.Gateway.AdvertiseUrls = parseHostName(c.Gateway.AdvertiseUrls)
213+
214+
hosts := extractHosts(c.Peer.AdvertiseUrls)
215+
if len(hosts) > 0 {
216+
env.SetEnv("PEER_ADVERTISE_HOSTS", strings.Join(hosts, ","))
217+
}
218+
hosts = extractHosts(c.Client.AdvertiseUrls)
219+
if len(hosts) > 0 {
220+
env.SetEnv("CLIENT_ADVERTISE_HOSTS", strings.Join(hosts, ","))
221+
}
222+
hosts = extractHosts(c.Gateway.AdvertiseUrls)
223+
if len(hosts) > 0 {
224+
env.SetEnv("GATEWAY_ADVERTISE_HOSTS", strings.Join(hosts, ","))
225+
}
226+
}
227+
228+
func extractHosts(addrs []string) []string {
229+
var hosts []string
230+
hostMap := map[string]struct{}{}
231+
for _, u := range addrs {
232+
parsedURL, err := url.Parse(u)
233+
if err != nil {
234+
log.Errorf("parse advertise url(%s) error: %v", u, err)
235+
continue
236+
}
237+
index := strings.Index(parsedURL.Host, ":")
238+
host := parsedURL.Host
239+
if index >= 0 {
240+
host = parsedURL.Host[:index]
241+
}
242+
if _, ok := hostMap[host]; ok {
243+
continue
244+
}
245+
hostMap[host] = struct{}{}
246+
hosts = append(hosts, host)
247+
}
248+
return hosts
209249
}

eoscli/extender.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ package eoscli
322322
// }
323323
// log.Debugf("name: %s\n", extends.FormatProject(group, project))
324324
// log.Debugf("version: %s %s\n", info.Version, isLatest)
325-
// log.Debugf("description:%s\n", info.Description)
325+
// log.Debugf("description:%s\n", info.Title)
326326
// log.Debugf("download url:%s\n", info.URL)
327327
// log.Debugf("install to run:%s extender install %s\n", os.Args[0], info.ID)
328328
// }

open-api/proxy.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package open_api
22

33
import (
44
"encoding/json"
5+
"net/http"
6+
57
"github.com/eolinker/eosc/log"
68
"github.com/julienschmidt/httprouter"
7-
"net/http"
89
)
910

1011
type OpenApiHandler interface {
@@ -40,7 +41,7 @@ func CreateHandler(handler OpenApiHandler) httprouter.Handle {
4041

4142
case string:
4243
data = []byte(d)
43-
log.Debug("handler write string:", string(d))
44+
log.Debug("handler write string:", d)
4445

4546
case []byte:
4647
data = d

process-admin/api-http/openapi-worker-save.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ func (oe *WorkerApi) Save(r *http.Request, params httprouter.Params) (status int
183183
cb.Version = admin.GenVersion()
184184
}
185185
cb.Profession = profession
186+
cb.Id, _ = eosc.ToWorkerId(name, profession)
186187
cb.Name = name
187188
cb.Update = eosc.Now()
188189
cb.Create = eosc.Now()
@@ -196,7 +197,9 @@ func (oe *WorkerApi) Save(r *http.Request, params httprouter.Params) (status int
196197
out = w
197198
return nil
198199
})
199-
200+
if err != nil {
201+
return http.StatusInternalServerError, nil, err
202+
}
200203
return http.StatusOK, nil, out.Detail()
201204
}
202205

setting/setting.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ package setting
33
import (
44
"encoding/json"
55
"fmt"
6-
"github.com/eolinker/eosc"
7-
"github.com/eolinker/eosc/common/bean"
8-
"github.com/eolinker/eosc/log"
96
"reflect"
107
"strings"
118
"sync"
9+
10+
"github.com/eolinker/eosc"
11+
"github.com/eolinker/eosc/common/bean"
12+
"github.com/eolinker/eosc/log"
1213
)
1314

1415
var (
@@ -79,7 +80,7 @@ func (s *tSettings) GetConfigBody(name string) ([]byte, bool) {
7980
// Create: eosc.Now(),
8081
// Update: eosc.Now(),
8182
// Body: outputBody,
82-
// Description: "",
83+
// Title: "",
8384
// },
8485
// }
8586
// delete = nil

0 commit comments

Comments
 (0)