Skip to content

Commit b614a13

Browse files
authored
merge: pull request #5 from sdressler/feature/hostname
Fixes #6: add hostname option to Augment
2 parents c455d45 + 42de800 commit b614a13

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

barf.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func createServer(a typing.Augment) error {
4949

5050
// create server
5151
server.HTTP = &http.Server{
52-
Addr: server.Augment.Port,
52+
Addr: fmt.Sprintf("%s:%s", server.Augment.Host, server.Augment.Port),
5353
ReadTimeout: time.Duration(server.Augment.ReadTimeout) * time.Second,
5454
WriteTimeout: time.Duration(server.Augment.WriteTimeout) * time.Second,
5555
MaxHeaderBytes: server.Augment.MaxHeaderBytes,
@@ -80,6 +80,7 @@ func Stark(augmentation ...typing.Augment) error {
8080
ReadHeaderTimeout: constant.ReadTimeout,
8181
WriteTimeout: constant.WriteTimeout,
8282
ShutdownTimeout: constant.ShutdownTimeout,
83+
Host: constant.Host,
8384
Port: constant.Port,
8485
Logging: &constant.Logging,
8586
Recovery: &constant.Recovery,
@@ -107,8 +108,11 @@ func Stark(augmentation ...typing.Augment) error {
107108
if aug.WriteTimeout != 0 {
108109
augu.WriteTimeout = aug.WriteTimeout
109110
}
111+
if aug.Host != "" {
112+
augu.Host = aug.Host
113+
}
110114
if aug.Port != "" {
111-
augu.Port = fmt.Sprintf(":%s", aug.Port)
115+
augu.Port = aug.Port
112116
}
113117
if aug.ReadHeaderTimeout != 0 {
114118
augu.ReadHeaderTimeout = aug.ReadHeaderTimeout
@@ -147,7 +151,7 @@ func Beck() error {
147151
shutdown()
148152
}()
149153
// start server
150-
logger.Info(fmt.Sprintf("BARF server started at http://localhost%s", server.Augment.Port))
154+
logger.Info(fmt.Sprintf("BARF server started at http://%s:%s", server.Augment.Host, server.Augment.Port))
151155
if err := server.HTTP.ListenAndServe(); err != nil {
152156
server.Beckoned = nil
153157
return err

constant/barf.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ const (
2525
// request line. It does not limit the size of the request body.
2626
MaxHeaderBytes = 1 << 20 // 1 MB
2727

28+
// Host is the host for the server to listen on
29+
Host = "127.0.0.1"
30+
2831
// Port is the port for the server to listen on
29-
Port = ":21186"
32+
Port = "21186"
3033

3134
// EnvPath is the path to the environment variables file
3235
EnvPath = ".env"

typing/barf.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ type Augment struct {
2222
// ShutdownTimeout is the time in seconds to wait for the server to shutdown gracefully
2323
// default is 5 seconds
2424
ShutdownTimeout int
25+
// Host is the host for the server to listen on
26+
Host string
2527
// Port is the port for the server to listen on
2628
Port string
2729
// ReadHeaderTimeout is the amount of time allowed to read

0 commit comments

Comments
 (0)