-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
40 lines (34 loc) · 746 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
34
35
36
37
38
39
40
package main
import (
"errors"
"fmt"
"log"
)
var (
baseconv, _ = NewBaseConvertor(62)
errInvalidLink = errors.New("short link too large")
config *Configuration
)
func main() {
config = ReadConfig()
fmt.Println(config)
var (
counterRepo CounterRepository
linkRepo LinkRepository
)
if config.DBTYPE == "mongodb" {
mongodb := NewMongoDBRepository()
linkRepo = mongodb
counterRepo = mongodb
} else if config.DBTYPE == "postgresql" {
postgresql := NewPostgreSQLRepository()
linkRepo = postgresql
counterRepo = postgresql
} else {
log.Fatal("Unrecognized DBTYPE")
}
service := &ServiceImpl{linkRepo, counterRepo}
router := NewRouter(service)
router.Run(":" + config.Port)
defer service.close()
}