-
Notifications
You must be signed in to change notification settings - Fork 0
/
yml.go
81 lines (61 loc) · 1.57 KB
/
yml.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"gopkg.in/yaml.v2"
)
type Config struct {
VerifyToken string `yaml:"verify_token"`
AccessToken string `yaml:"access_token"`
AppSecret string `yaml:"app_secret"`
}
/**
* Here, we wan to parse the yml file retrieve our specified content file
* We will then pass this to appropriate functions. For example: Reply a user
**/
func parseContentFile() string {
contentFile, err := ioutil.ReadFile("content.yml")
if err != nil {
log.Printf("Error opening content file: %s\n\n", err)
panic("ERROR OPENING CONTENT FILE" + err.Error())
}
er, _ := yaml.Marshal(contentFile)
if er != nil {
log.Printf("Couldnt marshal content file: %s\n\n", er)
}
return string(er)
}
// func getContents() string {
// var c MessageStruct
// c.parseContentFile()
// v, err := json.Marshal(c)
// if err != nil {
// log.Printf("Error marshalling our json file: %s\n", err)
// }
// return string(v)
// }
func (c *Config) readYml() *Config {
yamlFile, err := ioutil.ReadFile("bot.config.yml")
if err != nil {
log.Printf("Error opening config file: %s\n\n", err)
}
err = yaml.Unmarshal(yamlFile, c)
if err != nil {
log.Printf("Couldn't marshal config file:: %s\n", err)
}
//print out the parse file <@for debug only?@>
fmt.Printf("Here is the parsed content.yml: %s\n\n", c)
return c
}
func getToken() string {
var c Config
c.readYml()
v, err := json.Marshal(c)
//if there was an error Marshaling our struct to json
if err != nil {
log.Printf("Error marshalling our json file:: %s\n", err)
}
return string(v)
}