-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
33 lines (26 loc) · 823 Bytes
/
main.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
package main
import (
"database/sql"
"log"
"net/http"
"github.com/ClickHouse-Ninja/clickhouse-dictionary-api/src/dictionary"
_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"
)
var sources = make(map[string]*sql.DB)
func main() {
if err := dictionary.RegisterSources(config.Sources); err != nil {
log.Fatalf("an error occurred during registration of the source: %v", err)
}
for name, dict := range config.Dictionaries {
if handler, err := dictionary.Handler(&dict); err == nil {
log.Println("add handler: /dictionary/" + name)
http.HandleFunc("/dictionary/"+name, handler)
} else {
log.Fatalf("could not add dictionary handler: %v", err)
}
}
if err := http.ListenAndServe(config.Address, nil); err != nil {
log.Fatalf("could not bind address '%s': %v", config.Address, err)
}
}