Skip to content

Instantly share code, notes, and snippets.

Created Apr 26, 2016
What would you like to do?
// Copygright 2016 Google Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// Unless required by applicable law or agreed to writing, software distributed
// under the License is distributed on a "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package events
import (
func init() {
r := mux.NewRouter()
r.HandleFunc("/api/events", listEvents).Methods("GET")
r.HandleFunc("/api/events", addEvent).Methods("POST")
func listEvents(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
fmt.Fprintln(w, listOutput)
func addEvent(w http.ResponseWriter, r *http.Request) {
// : define an http.HandleFunc named listEvents
// When called it should simply print the contents of the listOutput constant declared below.
// You can also create a new App Engine context and use it to log some message.
// : define an http.HandleFunc named addEvent
// When called it should simply set the status code to 201 and log a message.
const listOutput = `
"title": "Craft Conf",
"description": "CRAFT is about software craftsmanship, which tools, methods, practices should be part of the toolbox of a modern developer and company.",
"date": "2016-04-26T00:00:00Z",
"location": "Budapest"
"title": "Google I/O",
"description": "Google I/O is for developers - the creative coders who are building what's next. Each year, we explore the latest in tech, mobile \u0026 beyond.",
"date": "2016-04-28T00:00:00Z",
"location": "Mountain View"
"title": "GopherCon China",
"description": "GOPHER'S BIGGEST PARTY",
"date": "2016-05-18T00:00:00Z",
"location": "Beijing"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment