hello.go 504 B

12345678910111213141516171819202122232425262728
  1. package main
  2. import (
  3. "github.com/hoisie/web";
  4. "encoding/json";
  5. "runtime";
  6. "os";
  7. "log";
  8. )
  9. type MessageStruct struct {
  10. Message string
  11. }
  12. func hello(val string) string {
  13. m := MessageStruct{"Hello, world"}
  14. j, _ := json.Marshal(m)
  15. return string(j)
  16. }
  17. func main() {
  18. f, _ := os.Create("server.log")
  19. logger := log.New(f, "", log.Ldate|log.Ltime)
  20. runtime.GOMAXPROCS(runtime.NumCPU())
  21. web.Get("/(.*)", hello)
  22. web.SetLogger(logger)
  23. web.Run("0.0.0.0:8080")
  24. }