-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
40 lines (32 loc) · 1001 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 (
"github.com/qiangxue/fasthttp-routing"
"github.com/valyala/fasthttp"
"github.com/sou-chon/proxy-go/s3Client"
"github.com/sou-chon/proxy-go/configType"
"fmt"
"encoding/json"
"os"
"io/ioutil"
)
func main() {
/* reading from config file */
configFile, err := os.Open("config.json")
if err != nil {
panic(err)
}
defer configFile.Close()
/* parsing config file TO_DO: what if config file does not conform to type? */
byteValue, _ := ioutil.ReadAll(configFile)
var config configType.Config
json.Unmarshal(byteValue, &config)
/* create connections */
clientpool := s3Client.InitialiseS3ClientPool(config.Stores)
router := routing.New()
router.Get("/<store>/<project>/<resource:[^ ]+>", HandleGetResourceRequestEnv(&clientpool, config.AccessTokens))
router.Get("/", func(ctx *routing.Context) error {
fmt.Fprintf(ctx, "Go to /<store>/<project>/<resource> for objects.")
return nil
})
panic(fasthttp.ListenAndServe(":8080", router.HandleRequest))
}