title: Concatenating a string to a slice of structs
body: <p>I'm trying to create an endpoint Go API to be consumed by front end JavaScript graphing library.</p>
  
  <p>What should happen:</p>
  
  <ol>
  <li>/data endpoint to get an array of JSON data.</li>
  <li>The data is just a slice of go structs, just two in this example but it will be over 10000.</li>
  <li>The graphing library expects additional meta data. It's saved as a variable called AdditionalInfo.</li>
  <li>The problem is when I want to encode the AdditionalInfo + AllAgents it won't let me join a string with a slice of structs. </li>
  <li>At the end of the slice of structs there also needs to be ]` to make it valid JSON</li>
  </ol>
  
  <p>Problems: </p>
  
  <ol>
  <li>How do you add additional data at the front and back the slice of structs? </li>
  <li>Is appending a struct to a slice of structs efficient? </li>
  <li><p>Would it be better to create a slice with a known length and then use range to append to it? </p>
  
  <pre><code>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",
  }
  </code></pre></li>
  </ol>