Skip to content

Instantly share code, notes, and snippets.

@lotusirous
Created January 17, 2020 07:22
Show Gist options
  • Select an option

  • Save lotusirous/c26d93b87e611fec4f2e74f8c523d069 to your computer and use it in GitHub Desktop.

Select an option

Save lotusirous/c26d93b87e611fec4f2e74f8c523d069 to your computer and use it in GitHub Desktop.
package main
import (
"context"
"net/http"
"github.com/go-chi/chi"
"github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"
)
// HandleIndex writes cookie to brower
func HandleIndex() http.HandlerFunc {
fn := func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cookie", "__session__=1")
}
return http.HandlerFunc(fn)
}
func main() {
ctx := context.Background()
var g errgroup.Group
r := chi.NewRouter()
r.Get("/", HandleIndex())
s := http.Server{
Addr: ":3000",
Handler: r,
}
g.Go(func() error {
return s.ListenAndServe()
})
g.Go(func() error {
<-ctx.Done()
return s.Shutdown(ctx)
})
if err := g.Wait(); err != nil {
logrus.Debugln("server stopped", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment