Skip to content

Commit 61cb00f

Browse files
committed
add listen host
1 parent d49df5e commit 61cb00f

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

config/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const (
1919
type AppConfig struct {
2020
Name string
2121
Mode string
22+
Host string
2223
Port int
2324
Log LogConfig
2425
Mysql MysqlConfig

service/app.go

+1
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ func (app *App) LoadConfig(mode string) *cfg.AppConfig {
220220
func appConfig(c *cfg.AppConfig) {
221221
c.Name = viper.GetString("app.name")
222222
c.Mode = viper.GetString("app.runMode")
223+
c.Host = viper.GetString("app.host")
223224
c.Port = viper.GetInt("app.port")
224225
}
225226

service/mysql.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ package service
22

33
import (
44
"container/ring"
5+
"fmt"
56
"io"
67
"log"
7-
8-
"fmt"
9-
108
"os"
119

1210
_ "github.com/go-sql-driver/mysql"
@@ -58,12 +56,12 @@ func NewMysqlManager(app Application, config config.MysqlConfig) (*MysqlManager,
5856
mm.readOnlyRing = mm.readOnlyRing.Next()
5957
mm.databases[instance.Name] = engine
6058
} else {
61-
fmt.Printf("WARNING when initializing MySQL: %s \n", err)
59+
log.Fatalf("WARNING when initializing MySQL: %s \n", err)
6260
}
6361
} else {
6462
engine, err = mm.newORM(instance)
6563
if err != nil {
66-
log.Fatal(err)
64+
log.Fatalf("mysql instance: %+v, err: %v", instance, err)
6765
}
6866
mm.master = engine
6967
mm.databases[instance.Name] = mm.master

service/rpc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (app *GrpcApp) Initialize() {
4343

4444
// ListenAndServe implements the GrpcApplication interface
4545
func (app *GrpcApp) ListenAndServe() {
46-
var port = fmt.Sprintf(":%d", app.GetConfig().Port)
46+
var port = fmt.Sprintf("%s:%d", app.GetConfig().Host, app.GetConfig().Port)
4747
l, err := net.Listen("tcp", port)
4848
if err != nil {
4949
log.Fatalf("failed to listen: %v", err)

service/web.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (app *WebApp) ListenAndServe() {
6464
func graceStart(app *WebApp) error {
6565
// Start server
6666
go func() {
67-
if err := app.Router.Start(fmt.Sprintf(":%d", app.Config.Port)); err != nil {
67+
if err := app.Router.Start(fmt.Sprintf("%s:%d", app.Config.Host, app.Config.Port)); err != nil {
6868
log.Fatal(err)
6969
}
7070
}()

0 commit comments

Comments
 (0)