This repository was archived by the owner on Dec 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkuenea.go
75 lines (59 loc) · 1.56 KB
/
kuenea.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"flag"
"fmt"
"log"
"net/http"
"strings"
"time"
"github.com/nassor/kuenea/conf"
"github.com/nassor/kuenea/handler"
)
func main() {
config, err := loadConfig()
if err != nil {
log.Fatalf("Could not load configuration: %v", err.Error())
}
err = loadGridsFS(config)
if err != nil {
log.Fatalf("Could not load databases: %v", err.Error())
}
err = loadPaths(config)
if err != nil {
log.Fatalf("Could not load paths: %v", err.Error())
}
log.Println("Starting Kuenea file server at " + config.BindWithPort())
s := &http.Server{
Addr: config.BindWithPort(),
ReadTimeout: time.Duration(config.HTTP.Timeout) * time.Millisecond,
WriteTimeout: 0}
log.Fatal(s.ListenAndServe())
}
func loadConfig() (conf.Config, error) {
var config conf.Config
var configFile = flag.String("c", "", "location of the configuration file")
flag.Parse()
if *configFile == "" {
*configFile = "/etc/kuenea/kuenea-config.yaml"
}
err := config.ReadConfigFile(*configFile)
if err != nil {
log.Fatalf("Can't open configuration file (%s)", configFile)
return config, err
}
return config, nil
}
func loadGridsFS(config conf.Config) error {
for _, gridConf := range config.GridFS {
http.Handle(fmt.Sprintf("/%v", gridConf.Path), handler.GridFSServer(gridConf))
}
return nil
}
func loadPaths(config conf.Config) error {
for _, localConf := range config.Local {
localConf.Path = strings.Trim(localConf.Path, "/")
localConf.Path = "/" + localConf.Path + "/"
http.Handle(localConf.Path, handler.LocalFSServer(localConf))
}
return nil
}