Skip to content

Instantly share code, notes, and snippets.

@laser
Created May 12, 2014 20:34
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 laser/f1cb9163fd43a0daf8df to your computer and use it in GitHub Desktop.
Save laser/f1cb9163fd43a0daf8df to your computer and use it in GitHub Desktop.
Basic Server - Golang
package main
import (
"fmt"
"github.com/coopernurse/barrister-go"
"net/http"
t "./todos"
s "./store"
)
type TodoManagerImpl struct {
Store *s.Store
}
func (impl TodoManagerImpl) ReadTodos() ([]t.Todo, error) {
return impl.Store.GetAll()
}
func (impl TodoManagerImpl) CreateTodo(properties t.TodoProperties) (t.Todo, error) {
return impl.Store.Save(properties)
}
func (impl TodoManagerImpl) UpdateTodo(todo t.Todo) (t.Todo, error) {
return impl.Store.Update(todo)
}
func (impl TodoManagerImpl) DeleteTodo(todo t.Todo) (bool, error) {
return impl.Store.Delete(todo.Id)
}
func main() {
idl := barrister.MustParseIdlJson([]byte(t.IdlJsonRaw))
store := s.NewStore()
mgr := TodoManagerImpl{store}
svr := t.NewJSONServer(idl, true, mgr)
http.Handle("/v1/todos", &svr)
fmt.Println("Starting TodoManager server on localhost:3000")
err := http.ListenAndServe(":3000", nil)
if err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment