38 lines
878 B
Go
38 lines
878 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"log"
|
|
"net/http"
|
|
)
|
|
|
|
// abocost handler
|
|
func abocostHandler(response http.ResponseWriter, request *http.Request) {
|
|
body, err := ioutil.ReadAll(request.Body)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
log.Println(string(body))
|
|
|
|
var data map[string]int
|
|
err2 := json.Unmarshal([]byte(body), &data)
|
|
if err2 != nil {
|
|
log.Println("Error, invalid json: %v", err)
|
|
}
|
|
response.Header().Set("Content-Type", "text/json; charset=utf-8")
|
|
fmt.Fprintf(response, "{\n")
|
|
first := true
|
|
for key, value := range data {
|
|
fmt.Println("Key:", key, "Value:", value)
|
|
if first {
|
|
first = false
|
|
} else {
|
|
fmt.Fprintf(response, " ,")
|
|
}
|
|
fmt.Fprintf(response, " \"%s\": [ %d, %d, \"%s\", \"%s\" ]\n", key, int(value), int(getYearlyAboCost(key)*int(value)), getActiveUntil(key), getDevAlias(key))
|
|
}
|
|
fmt.Fprintf(response, "}\n")
|
|
}
|