Created
May 12, 2014 20:34
-
-
Save laser/f1cb9163fd43a0daf8df to your computer and use it in GitHub Desktop.
Basic Server - Golang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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