-
Notifications
You must be signed in to change notification settings - Fork 10
/
config.go
65 lines (56 loc) · 1.75 KB
/
config.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
/**
*
* AnsCDN Copyright (C) 2010 Robin Syihab (r [at] nosql.asia)
* Simple CDN server written in Golang.
*
* License: General Public License v2 (GPLv2)
*
* Copyright (c) 2009 The Go Authors. All rights reserved.
*
**/
package config
import (
"os"
"./configfile"
)
type AnscdnConf struct {
BaseServer string
ServingPort int
StoreDir string
ApiStorePrefix string
Strict bool
CacheOnly bool
FileMon bool
CacheExpires int64
ClearCachePath string
IgnoreNoExt bool
IgnoreExt string
ProvideApi bool
ApiKey string
CdnServerName string
UrlMap string
}
func Parse(file string) (ac *AnscdnConf, err os.Error) {
conf, err := configfile.ReadConfigFile(file)
if err != nil{
return nil, err
}
BaseServer, err := conf.GetString("default","base_server")
ServingPort, err := conf.GetInt("default","serving_port")
StoreDir, err := conf.GetString("default","store_dir")
Strict, err := conf.GetBool("default","strict")
CacheOnly, err := conf.GetBool("default","cache_only")
FileMon, err := conf.GetBool("default","file_mon")
CacheExpires, err := conf.GetInt64("default","cache_expires")
ClearCachePath, err := conf.GetString("default","clear_cache_path")
IgnoreNoExt, err := conf.GetBool("default","ignore_no_ext")
IgnoreExt, err := conf.GetString("default","ignore_ext")
ProvideApi, err := conf.GetBool("default","provide_api")
ApiKey, err := conf.GetString("default","api_key")
CdnServerName, err := conf.GetString("default", "cdn_server_name")
UrlMap, err := conf.GetString("default", "url_map")
ApiStorePrefix, err := conf.GetString("default", "api_store_prefix")
return &AnscdnConf{BaseServer,
ServingPort, StoreDir, ApiStorePrefix, Strict,CacheOnly,FileMon,CacheExpires,
ClearCachePath,IgnoreNoExt,IgnoreExt, ProvideApi,ApiKey,CdnServerName,UrlMap}, err
}