Skip to content

Commit 4594980

Browse files
committed
update registrar to expect address instead of expecting domain
1 parent baabf66 commit 4594980

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

node-registrar/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
run:
2-
go run cmds/main.go --postgres-host localhost --postgres-port 5432 --postgres-db postgres --postgres-user postgres --postgres-password password --domain localhost --server-port 8080
2+
go run cmds/main.go --postgres-host localhost --postgres-port 5432 --postgres-db postgres --postgres-user postgres --postgres-password password --address localhost --server-port 8080
33

44
start-postgres:
55
docker run --name postgres -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password -e POSTGRES_DB=postgres -p 5432:5432 -d postgres
@@ -14,7 +14,7 @@ server-start:
1414
@go run cmds/main.go \
1515
--server-port 8080 \
1616
--debug \
17-
--domain localhost \
17+
--address localhost \
1818
--sql-log-level 4 \
1919
--postgres-host localhost \
2020
--postgres-port 5432 \

node-registrar/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ It offers operations like registring, listing, and updating farms and nodes, as
7676
Once the server is running, Swagger documentation can be accessed at:
7777

7878
```bash
79-
http://<domain>:<port>/swagger/index.html
79+
http://<address>:<port>/swagger/index.html
8080
```
8181

82-
Replace `<domain>` and `<port>` with the appropriate values.
82+
Replace `<address>` and `<port>` with the appropriate values.
8383

8484
## How to Use the Server
8585

@@ -112,7 +112,7 @@ docker build -t registrar:latest -f node-registrar/Dockerfile .
112112
--max-open-conn=10 \
113113
--max-idle-conn=5 \
114114
--server-port=8080 \
115-
--<domain=your-domain> \
115+
--<address=your-address-or-domain> \
116116
--network=main\
117117
--admin_twin_id=1
118118
--debug

node-registrar/cmds/main.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type flags struct {
1919
db.Config
2020
debug bool
2121
version bool
22-
domain string
22+
addr string
2323
serverPort uint
2424
network string
2525
adminTwinID uint64
@@ -53,7 +53,7 @@ func Run() error {
5353
flag.BoolVar(&f.version, "v", false, "shows the package version")
5454
flag.BoolVar(&f.debug, "debug", false, "allow debug logs")
5555
flag.UintVar(&f.serverPort, "server-port", 8080, "server port")
56-
flag.StringVar(&f.domain, "domain", "", "domain on which the server will be served")
56+
flag.StringVar(&f.addr, "address", "", "address or domain on which the server will be served")
5757
flag.StringVar(&f.network, "network", "dev", "the registrar network")
5858
flag.Uint64Var(&f.adminTwinID, "admin-twin-id", 1, "admin twin ID")
5959

@@ -91,7 +91,7 @@ func Run() error {
9191

9292
log.Info().Msgf("server is running on port :%d", f.serverPort)
9393

94-
err = s.Run(fmt.Sprintf("%s:%d", f.domain, f.serverPort))
94+
err = s.Run(fmt.Sprintf("%s:%d", f.addr, f.serverPort))
9595
if err != nil {
9696
return errors.Wrap(err, "failed to run gin server")
9797
}
@@ -104,19 +104,27 @@ func (f flags) validate() error {
104104
return errors.Errorf("invalid port %d, server port should be in the valid port range 1–65535", f.serverPort)
105105
}
106106

107-
if strings.TrimSpace(f.domain) == "" {
108-
return errors.New("invalid domain name, domain name should not be empty")
109-
}
110-
111107
if f.Config.SqlLogLevel < 1 || f.Config.SqlLogLevel > 4 {
112108
return errors.Errorf("invalid sql log level %d, sql log level should be in the range 1-4", f.Config.SqlLogLevel)
113109
}
114110
if f.adminTwinID == 0 {
115111
return errors.Errorf("invalid admin twin id %d, admin twin id should not be 0", f.adminTwinID)
116112
}
117113

118-
if _, err := net.LookupHost(f.domain); err != nil {
119-
return errors.Wrapf(err, "invalid domain %s", f.domain)
114+
if strings.TrimSpace(f.addr) == "" {
115+
return errors.New("invalid domain/address, should not be empty")
116+
}
117+
118+
// Skip validation for common binding addresses
119+
if f.addr == "0.0.0.0" || f.addr == "localhost" || f.addr == "127.0.0.1" {
120+
return f.Config.Validate()
121+
}
122+
123+
if net.ParseIP(f.addr) == nil {
124+
// if not valid IP address, check if valid domain
125+
if _, err := net.LookupHost(f.addr); err != nil {
126+
return errors.Wrapf(err, "invalid domain %s", f.addr)
127+
}
120128
}
121129

122130
return f.Config.Validate()

0 commit comments

Comments
 (0)