-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
38 lines (32 loc) · 661 Bytes
/
main.go
File metadata and controls
38 lines (32 loc) · 661 Bytes
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
package main
import (
"fmt"
"net/http"
"od2kproxy/od2kproxy"
"github.com/spf13/viper"
)
func init() {
viper.AddConfigPath(".")
viper.SetConfigName("settings")
viper.SetConfigType("json")
err := viper.ReadInConfig()
if err != nil {
panic(fmt.Errorf("fatal error config file: %s", err))
}
}
func main() {
portSetting := viper.GetString("http_port")
if portSetting == "" {
panic(fmt.Errorf("port is required"))
}
port := fmt.Sprintf(":%s", portSetting)
client, err := od2kproxy.NewProxyClient()
if err != nil {
panic(err)
}
http.HandleFunc("/", client.Handler)
err = http.ListenAndServe(port, nil)
if err != nil {
panic(err)
}
}