|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "encoding/json" |
| 5 | + "errors" |
| 6 | + "fmt" |
| 7 | + "io/ioutil" |
| 8 | + "log" |
| 9 | + |
| 10 | + "./task" |
| 11 | + |
| 12 | + "gopkg.in/yaml.v2" |
| 13 | +) |
| 14 | + |
| 15 | +type taskConfig struct { |
| 16 | + TOKEN string `yaml:"token"` |
| 17 | + APIURL string `yaml:"api"` |
| 18 | + TASKNUM int `yaml:"taskNum"` |
| 19 | +} |
| 20 | + |
| 21 | +func (c *taskConfig) getConf() (*taskConfig, error) { |
| 22 | + |
| 23 | + yamlFile, err := ioutil.ReadFile("conf.yaml") |
| 24 | + if err != nil { |
| 25 | + log.Printf("[ERROR] yamlFile.Get err #%v ", err) |
| 26 | + return nil, errors.New("Cant not read config.yaml") |
| 27 | + } |
| 28 | + err = yaml.Unmarshal(yamlFile, c) |
| 29 | + if err != nil { |
| 30 | + return nil, errors.New("Cant not prase config.yaml") |
| 31 | + } |
| 32 | + |
| 33 | + return c, nil |
| 34 | +} |
| 35 | + |
| 36 | +func main() { |
| 37 | + |
| 38 | + fmt.Println("Cloudreve Queue Go Version") |
| 39 | + fmt.Println("Author: AaronLiu <abslant@foxmail.com>") |
| 40 | + |
| 41 | + var config taskConfig |
| 42 | + _, err := config.getConf() |
| 43 | + if err == nil { |
| 44 | + log.Printf("[INFO] Config information: %v ", config) |
| 45 | + api := task.ApiInfo{TOKEN: config.TOKEN, APIURL: config.APIURL} |
| 46 | + basicInfo := api.GetBasicInfo() |
| 47 | + if basicInfo != "" { |
| 48 | + log.Printf("[INFO] Basic Info: %v ", basicInfo) |
| 49 | + var siteInfo map[string]string |
| 50 | + err := json.Unmarshal([]byte(basicInfo), &siteInfo) |
| 51 | + if err != nil { |
| 52 | + log.Printf("[ERROR] Failed to decode basic infomation, %v ", err.Error()) |
| 53 | + } |
| 54 | + for { |
| 55 | + taskListContent := api.GetTaskList(config.TASKNUM) |
| 56 | + task.Init(taskListContent, api) |
| 57 | + break |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + } |
| 62 | + |
| 63 | +} |
0 commit comments