Skip to content

Instantly share code, notes, and snippets.

@hourback
Created October 1, 2014 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hourback/28a708f13022413ed616 to your computer and use it in GitHub Desktop.
Save hourback/28a708f13022413ed616 to your computer and use it in GitHub Desktop.
Trying to create fixture data on line 31-32, but getting . . . "2014/10/01 19:16:02 Creating records panic: runtime error: index out of range goroutine 1 [running]: runtime.panic(0x6186e0, 0x8c48f7) /usr/lib/go/src/pkg/runtime/panic.c:266 +0xb6 main.main() /data/docker-ember.js/fanotification/go-net-http/server.go:32 +0x4f9"
package main
import (
_ "github.com/lib/pq"
//"database/sql"
//"github.com/jmoiron/sqlx"
"log"
"io"
"net/http"
)
type Notification struct {
Id string
Status string
DescriptionOfProblem string
}
func HelloServer(w http.ResponseWriter, req *http.Request) {
io.WriteString(w, "hello, world!\n")
}
func AllNotifications(w http.ResponseWriter, req *http.Request) {
io.WriteString(w, "This will list all of the notifications in the database.\n")
}
func main() {
log.Println("Starting server")
log.Println("Creating records")
people := []Notification{}
people[0] = Notification{Id: "1", Status: "OPEN", DescriptionOfProblem: "Blah"}
log.Println(people)
http.HandleFunc("/hello", HelloServer)
http.HandleFunc("/api/notifications", AllNotifications)
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
} else {
log.Println("Listening on 8080")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment