Skip to content

Commit 667c67e

Browse files
committed
update registrar to expect address instead of expecting domain
1 parent 97a456a commit 667c67e

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
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 & 5 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
@@ -58,7 +58,7 @@ func Run() error {
5858
flag.BoolVar(&f.version, "v", false, "shows the package version")
5959
flag.BoolVar(&f.debug, "debug", false, "allow debug logs")
6060
flag.UintVar(&f.serverPort, "server-port", 8080, "server port")
61-
flag.StringVar(&f.domain, "domain", "", "domain on which the server will be served")
61+
flag.StringVar(&f.addr, "address", "", "address or domain on which the server will be served")
6262
flag.StringVar(&f.network, "network", "dev", "the registrar network")
6363
flag.Uint64Var(&f.adminTwinID, "admin-twin-id", 1, "admin twin ID")
6464

@@ -96,7 +96,7 @@ func Run() error {
9696

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

99-
err = s.Run(fmt.Sprintf("%s:%d", f.domain, f.serverPort))
99+
err = s.Run(fmt.Sprintf("%s:%d", f.addr, f.serverPort))
100100
if err != nil {
101101
return errors.Wrap(err, "failed to run gin server")
102102
}
@@ -120,8 +120,20 @@ func (f flags) validate() error {
120120
return errors.Errorf("invalid admin twin id %d, admin twin id should not be 0", f.adminTwinID)
121121
}
122122

123-
if _, err := net.LookupHost(f.domain); err != nil {
124-
return errors.Wrapf(err, "invalid domain %s", f.domain)
123+
if strings.TrimSpace(f.addr) == "" {
124+
return errors.New("invalid domain/address, should not be empty")
125+
}
126+
127+
// Skip validation for common binding addresses
128+
if f.addr == "0.0.0.0" || f.addr == "localhost" || f.addr == "127.0.0.1" {
129+
return f.Config.Validate()
130+
}
131+
132+
if net.ParseIP(f.addr) == nil {
133+
// if not valid IP address, check if valid domain
134+
if _, err := net.LookupHost(f.addr); err != nil {
135+
return errors.Wrapf(err, "invalid domain %s", f.addr)
136+
}
125137
}
126138

127139
return f.Validate()

0 commit comments

Comments
 (0)