Questions tagged [go-chi]

This tag should be used on questions related to the go-chi HTTP router.

go-chi is a lightweight router for building HTTP services, and especially REST API servers, in Go. It uses the context package introduced in Go 1.7 and aims at being fast, idiomatic and compatible with the standard Go net/http library.

68 questions
0
votes
1 answer

Does timeout causes an API endpoint trigger multiple times?

I have a GO Post API endpoint with a somewhat time-consuming task in the handler (time can be 2 minutes even, when I running it locally). In my FE I call the API once and it triggers only once (in the network tab, there are no multiple requests)…
Thidasa Pankaja
  • 930
  • 8
  • 25
  • 44
0
votes
1 answer

Clean way for same endpoints but with different API versions

I'm looking for a clean way to maintain two versions of an API that have the same endpoints. Right now, the easiest way but seems excessive is to have something like r := chi.NewRouter() r.Get("/test", func(w http.ResponseWriter, r…
sdum
  • 1
  • 1
0
votes
1 answer

Is it possible to differentiate a route on the same path but with a query?

I want to define methods on / and then on /?. So I did r.Get("/", myHandlers.Get) r.Get("/?id", myHandlers.GetById) But when I hit http://myurl/?id=xyz I never go to the GetById method. How can I differentiate them better in Go Chi?
zer0
  • 4,657
  • 7
  • 28
  • 49
0
votes
1 answer

Go chi middleware to add item to response header

My concept is simple, I would like to add the request ID (generated by chi middleware.RequestID to the response header). My code below adds X-Request-Id but does not add the ID itself. I am not sure why, since surely it is available in the context…
Little Code
  • 1,315
  • 2
  • 16
  • 37
0
votes
0 answers

404 instead of graphql playground when i use chi router or any router instead of http

whenever I change http with router I can't access my graphql playground when i use router instead of http with i get 404 func main() { port := os.Getenv("PORT") if port == "" { port = defaultPort } router := chi.NewRouter() …
0
votes
0 answers

404 Error when passing params to URL in go-chi even though the params are defined

I want to take limit and offset values from my frontend. For that, I have written the following routing path func (s *Server) stockRoutes() { s.r.Route("/stock", func(r chi.Router) { r.Get("/{limit}{offset}", s.ListStocks(s.ctx)) …
neel229
  • 73
  • 1
  • 5
0
votes
1 answer

Wrapping a handler with a middleware that has parameters with Go-chi

i've been trying to implement this tutorial with go-chi and especially the part about wrapping / passing an argument to a wrapper. My goal is to be able to wrap some specific routes with a middleware with custom parameters for that route instead of…
kijawi21
  • 13
  • 1
  • 2
0
votes
0 answers

How to save remote IP address in Postgres with Go?

I am trying to save incoming request's remote IP address into Postgres. I am using chi and sqlc. Here's the migration: CREATE TABLE IF NOT EXISTS ips ( id bigserial PRIMARY KEY, ip INET ); And this is the insert query: -- name: CreateIp…
Swix
  • 1,883
  • 7
  • 33
  • 50
0
votes
1 answer

Adding authentication middleware with go-chi router for GraphQL with gqlgen

package main import ( "github.com/go-chi/chi" "go-graphql-demo/graph" "go-graphql-demo/graph/generated" "log" "net/http" "os" "github.com/99designs/gqlgen/graphql/handler" …
Shubham
  • 211
  • 2
  • 13
0
votes
1 answer

Go chi renderer having difficult processing bound lists

Go here. Trying to get the chi renderer to return a list of Order struct instances and getting a compiler error that I don't understand: package myapp import ( "net/http" "github.com/go-chi/render" ) type Order struct { OrderId …
hotmeatballsoup
  • 385
  • 6
  • 58
  • 136
0
votes
1 answer

Cannot connect to graphql playground when using go-chi router

I'm use gqlgen to create a go graphql server. In the tutorial, the default setup for localhost:8080 works fine. server.go ... func main() { srv := handler.NewDefaultServer(generated.NewExecutableSchema(generated.Config{Resolvers:…
Carrein
  • 3,231
  • 7
  • 36
  • 77
0
votes
0 answers

Attach middleware to routes mounted to the router

This might just be because of my inexperience, but I've taken over a webserver solution written in Go and I have some issues. The routing is set up in such a way that each "top" route is mounted to the router with router.Mount() with a handler…
Terris
  • 25
  • 8
0
votes
1 answer

go chi router with url parameters and mysql db not working properly

I am new to golang and working on a restful service in golang using chi. I am trying to create a route as below: func NewRouter(dm *storage.DatabaseManager) chi.Router { var router = chi.NewRouter() router.Method("POST",…
Hun ssh
  • 3
  • 1
  • 3
0
votes
3 answers

How enable gzip compression middleware in go-chi

How can I enable gzip compression using the gzip middleware of the go-chi framework? Try using the example shown here: https://github.com/go-chi/chi/issues/204 but when I check with curl, I get this: $ curl -H "Accept-Encoding: gzip" -I…
jhoss
  • 457
  • 3
  • 10
  • 19
0
votes
1 answer

Post Request with PostgreSQL and json-api returns an empty body

After a POST request, i was expecting to have a last inserted record marshalled into json, but instead returns an empty body. What am i not doing well? package models import ( "encoding/json" "errors" "flag" "fmt" "log" …
afidegnum
  • 161
  • 4
  • 21