mirror of
https://github.com/chubin/wttr.in
synced 2025-01-12 12:08:47 +00:00
Move server config to Config struct
This commit is contained in:
parent
7d801e3b4d
commit
5bb0c4f1fe
3 changed files with 19 additions and 2 deletions
|
@ -3,6 +3,7 @@ package main
|
||||||
// Config of the program.
|
// Config of the program.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Logging
|
Logging
|
||||||
|
Server
|
||||||
}
|
}
|
||||||
|
|
||||||
// Logging configuration.
|
// Logging configuration.
|
||||||
|
@ -15,10 +16,26 @@ type Logging struct {
|
||||||
Interval int
|
Interval int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Server configuration.
|
||||||
|
type Server struct {
|
||||||
|
|
||||||
|
// PortHTTP is port where HTTP server must listen.
|
||||||
|
// If 0, HTTP is disabled.
|
||||||
|
PortHTTP int
|
||||||
|
|
||||||
|
// PortHTTP is port where the HTTPS server must listen.
|
||||||
|
// If 0, HTTPS is disabled.
|
||||||
|
PortHTTPS int
|
||||||
|
}
|
||||||
|
|
||||||
// Conf contains the current configuration.
|
// Conf contains the current configuration.
|
||||||
var Conf = Config{
|
var Conf = Config{
|
||||||
Logging{
|
Logging{
|
||||||
AccessLog: "/wttr.in/log/access.log",
|
AccessLog: "/wttr.in/log/access.log",
|
||||||
Interval: 300,
|
Interval: 300,
|
||||||
},
|
},
|
||||||
|
Server{
|
||||||
|
PortHTTP: 8083,
|
||||||
|
PortHTTPS: 0,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,6 +95,7 @@ func (rl *RequestLogger) flush() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String returns string representation of logEntry.
|
||||||
func (e *logEntry) String() string {
|
func (e *logEntry) String() string {
|
||||||
return fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
"%s %s %s %s",
|
"%s %s %s %s",
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
lru "github.com/hashicorp/golang-lru"
|
lru "github.com/hashicorp/golang-lru"
|
||||||
)
|
)
|
||||||
|
|
||||||
const serverPort = 8083
|
|
||||||
const uplinkSrvAddr = "127.0.0.1:9002"
|
const uplinkSrvAddr = "127.0.0.1:9002"
|
||||||
const uplinkTimeout = 30
|
const uplinkTimeout = 30
|
||||||
const prefetchInterval = 300
|
const prefetchInterval = 300
|
||||||
|
@ -90,5 +89,5 @@ func main() {
|
||||||
w.Write(response.Body)
|
w.Write(response.Body)
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", serverPort), nil))
|
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", Conf.Server.PortHTTP), nil))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue