Go + koa = ? A new web framework goa

koajs

koa - Expressive middleware for node.js using ES2017 async functions

goa

What’ll happen when go with koa?
github:goa

Here is a demo:

package main

import (
  "fmt"
  "time"

  "github.com/goa-go/goa"
  "github.com/goa-go/goa/router"
)

func logger(c *goa.Context, next func()) {
  start := time.Now()

  fmt.Printf("[%s] <-- %s %s\n", start.Format("2006-6-2 15:04:05"), c.Method, c.URL)
  next()
  fmt.Printf("[%s] --> %s %s %d%s\n", time.Now().Format("2006-6-2 15:04:05"), c.Method, c.URL, time.Since(start).Nanoseconds()/1e6, "ms")
}

func json(c *goa.Context) {
  c.JSON(goa.M{
    "string": "string",
    "int":    1,
    "json": goa.M{
      "key": "value",
    },
  })
}

func main() {
  app := goa.New()
  router := router.New()

  router.GET("/", func(c *goa.Context) {
    c.String("hello world")
  })
  router.GET("/json", json)

  app.Use(logger)
  app.Use(router.Routes())
  app.Listen(":3000")
}

If u are interested in this project, plz give a star, pr is also welcome!

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.