-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
39 lines (32 loc) · 784 Bytes
/
app.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package sfsapp
import (
"log"
"net/http"
"os"
"github.com/bykovme/sfs/messages"
)
// App - main application
type App struct {
LoadedConfig Config
}
func (app *App) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var head string
head, r.URL.Path = ShiftPath(r.URL.Path)
switch head {
case "api":
app.ServeAPI(w, r)
default:
messages.PrepareErrorReply(w, messages.MSGAPI10002APINotFound, http.StatusMethodNotAllowed)
}
}
// GetPort returns default port either from config or from environment variable
// environment variable has priority
func (app *App) GetPort() string {
port := app.LoadedConfig.ServerPort
portEnv := os.Getenv("PORT")
if portEnv != "" {
port = portEnv
log.Println("Using port set in the environment, PORT=" + port)
}
return port
}