Skip to content
Snippets Groups Projects
Commit 2645817f authored by Hugo Hörnquist's avatar Hugo Hörnquist
Browse files

Interface based.

parent d8e60d08
No related branches found
No related tags found
No related merge requests found
......@@ -26,7 +26,7 @@ var client *http.Client
// echo curl --user "hugo:$(pass lysator/hugo)" -k https://chapman.lysator.liu.se/api/hosts
type Host struct {
Data ResultRecord
Data HostRecord
}
func Init(pw string) {
......@@ -41,8 +41,8 @@ func Init(pw string) {
client = &http.Client{Transport: tr}
var m Message
fff("hosts", &m)
var m HostMessage
fff_pages("hosts", &m)
for _, record := range m.Results {
Hosts[record.Name] = Host{record}
......@@ -69,13 +69,19 @@ func fff (url string, message interface{}) {
decoder := json.NewDecoder(resp.Body)
err = decoder.Decode(&message)
err = decoder.Decode(message)
if err != nil {
log.Fatal(err)
}
}
func fff_pages(url string, message IsMessage) {
fff(url, &message)
log.Printf("message = %+v", message.GetMessage())
}
func GetClassList(host ResultRecord) []string {
func GetClassList(host HostRecord) []string {
var record []Puppetclass
if val, ok := hostClasses[host.Id]; ok {
......@@ -83,7 +89,7 @@ func GetClassList(host ResultRecord) []string {
} else {
url := fmt.Sprintf("hosts/%d/puppetclasses", int(host.Id))
var m PuppetclassMessage
fff(url, &m)
fff_pages(url, &m)
for _, values := range m.Results {
record = append(record, values...)
......@@ -98,7 +104,7 @@ func GetClassList(host ResultRecord) []string {
return str
}
type ResultRecord struct {
type HostRecord struct {
Ip string // "130.236.254.139",
Ip6 string // "2001:6b0:17:f0a0::8b",
Environment_id float64 // 1,
......@@ -199,13 +205,28 @@ type ResultRecord struct {
Hostgroup_title string // "Analysator/System"
}
type IsMessage interface {
GetMessage() Message
// TODO
// MergeMessage(Message) Message
}
type Message struct {
Total, Subtotal, Page/*, Per_page*/ float64
Results []ResultRecord
Total, Subtotal, Page, Per_page float64
// search
// sort { by, order null }
}
type HostMessage struct {
Message
Results []HostRecord
}
func (m HostMessage) GetMessage() Message {
return m.Message
}
type Puppetclass struct {
Id float64
Name string // "profiles::localtime"
......@@ -214,6 +235,10 @@ type Puppetclass struct {
}
type PuppetclassMessage struct {
Total, Subtotal, Page, Per_page float64
Message
Results map[string][]Puppetclass
}
func (m PuppetclassMessage) GetMessage() Message {
return m.Message
}
......@@ -8,7 +8,6 @@ import (
)
type Data struct {
// record ResultRecord
Hostname string
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment