Было бы лучше создать срез известной длины, а затем использовать диапазон для добавления к нему?
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"os"
)
func main() {
port := os.Getenv("PORT")
if port == "" {
port = "443"
log.Printf("Defaulting to port %s", port)
}
http.HandleFunc("/data", TrySnipped)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil))
}
func TrySnipped(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")
var AllAgents []SingleAgent
AllAgents = append(AllAgents, FirstAgent)
AllAgents = append(AllAgents, SecondAgent)
json.NewEncoder(w).Encode(AllAgents)
}
var AdditionalInfo = `"meta": {
"page": 1,
"pages": 1,
"perpage": -1,
"total": 350,
"sort": "asc",
"field": "RecordID"
},
"data": [`
type SingleAgent struct {
RecordID string `json:"RecordID"`
OldEmployeeID string `json:"OldEmployeeID"`
NewEmployeeID string `json:"NewEmployeeID"`
AgentRank int `json:"AgentRank"`
AgentName string `json:"AgentName"`
AgentEmail string `json:"AgentEmail"`
TeamManager string `json:"TeamManager"`
LineOfBusiness string `json:"LineOfBusiness"`
FitnessCampStartDate string `json:"FitnessCampStartDate"`
FitnessCampEndDate string `json:"FitnessCampEndDate"`
FitnessCampStatus int `json:"FitnessCampStatus"`
AgentFitnessRank int `json:"AgentFitnessRank"`
LatestMetricA int `json:"MetricA"`
LatestMetricB int `json:"MetricB"`
LatestMetricC int `json:"MetricC"`
LatestMetricD int `json:"MetricD"`
LatestMetricE int `json:"MetricD"`
SiteName string `json:"SiteName"`
SiteID string `json:"SiteID"`
PostCampWeek1 string `json:"PostCampWeek1"`
PostCampWeek2 string `json:"PostCampWeek2"`
PostCampWeek3 string `json:"PostCampWeek3"`
}
var FirstAgent = SingleAgent{
RecordID: "30",
OldEmployeeID: "785114544",
NewEmployeeID: "10785114544",
AgentRank: 3,
AgentName: "Shandeigh Rawsen",
AgentEmail: "shandeigh.rawsen@gmail.com",
TeamManager: "Oliver Lamplugh",
LineOfBusiness: "BMS",
FitnessCampStartDate: "8/13/2018",
FitnessCampEndDate: "10/7/2018",
FitnessCampStatus: 1,
AgentFitnessRank: 1,
LatestMetricA: 77,
LatestMetricB: 167,
LatestMetricC: 496,
LatestMetricD: 72,
LatestMetricE: 80,
SiteName: "Montreal",
SiteID: "4",
PostCampWeek1: "10/2/2018",
PostCampWeek2: "10/9/2018",
PostCampWeek3: "10/19/2018",
}
var SecondAgent = SingleAgent{
RecordID: "29",
OldEmployeeID: "980433290",
NewEmployeeID: "10980433290",
AgentRank: 4,
AgentName: "Terrijo Dewberry",
AgentEmail: "terrijo.deberry@gmail.com",
TeamManager: "Oliver Lamplugh",
LineOfBusiness: "BTSW",
FitnessCampStartDate: "7/28/2018",
FitnessCampEndDate: "9/23/2018",
FitnessCampStatus: 2,
AgentFitnessRank: 2,
LatestMetricA: 88,
LatestMetricB: 92,
LatestMetricC: 716,
LatestMetricD: 78,
LatestMetricE: 66,
SiteName: "Montreal",
SiteID: "2",
PostCampWeek1: "10/2/2018",
PostCampWeek2: "10/9/2018",
PostCampWeek3: "10/15/2018",
}