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
14
votes
2 answers

golang Chi router with query params not working

I am working on a restful service in golang using chi. I am trying to create a route as below r.Mount("/api/dest", router.NewDestRouter(chi.NewRouter(), destSrv).InitRoutes()) func (dr *DestRouter) InitRoutes() http.Handler { …
DoIt
  • 3,270
  • 9
  • 51
  • 103
10
votes
1 answer

chi.URLParam not working when handler is defined outside main package

So I am new to go and I currently try to build a little REST-API using chi (and I love it). Yesterday I run into a problem, that I cannot quite understand. In my little test-project I have a main.go file which contains the main function with router…
BlackCat
  • 160
  • 2
  • 8
7
votes
4 answers

Testing Chi Routes w/Path Variables

I'm having trouble testing my go-chi routes, specifically the route with path variables. Running the server with go run main.go works fine and requests to the route with the path variable behaves as expected. When I run my tests for the routes, I…
John
  • 705
  • 3
  • 9
  • 18
4
votes
1 answer

Unable to read "request.Body" in Go Chi router

Consider the following code in main/entry function r := chi.NewRouter() r.Use(middleware.RequestID) r.Use(middleware.RealIP) r.Use(middleware.Logger) r.Use(middleware.Recoverer) r.Post("/book", controllers.CreateBook) …
Alok G.
  • 1,388
  • 3
  • 15
  • 26
4
votes
1 answer

Middleware on a specific route

As in go-chi, set middleware at the level of individual routes, and not just globally for all routes // Routes creates a REST router func Routes() chi.Router { r := chi.NewRouter() r.Use(middleware.Captcha) r.Post("/", Login) …
batazor
  • 852
  • 2
  • 16
  • 36
3
votes
1 answer

go-chi router override middleware to set content type

I have a go API which so far has always returned JSON. I use chi router and set it up using middleware like this in my main function: func router() http.Handler { r := chi.NewRouter() r.Use(render.SetContentType(render.ContentTypeJSON)) .... Now I…
markhorrocks
  • 1,199
  • 19
  • 82
  • 151
3
votes
3 answers

Difference between middleware chi.Use vs chi.With

What is the difference between chi.Use and chi.With when setting up a middleware with Chi router.
Gurleen Sethi
  • 3,162
  • 6
  • 26
  • 48
3
votes
1 answer

How to get url param in middleware go-chi

I use a specific middleware for specific set of routes r.Route("/platform", func(r chi.Router) { r.Use(authService.AuthMiddleware) r.Get("/{id}/latest", RequestPlatformVersion) }) Now how can I access id url param inside this AuthMiddleware…
Thidasa Pankaja
  • 930
  • 8
  • 25
  • 44
3
votes
1 answer

Gorm and go-chi REST patch resource

I am building a REST API using chi and gorm I want to have a patch route where I can update only the properties I receive in the request body. I am not sure how is the best way of passing there properties to gorm update method. Which would be a good…
aolivera
  • 512
  • 1
  • 4
  • 23
3
votes
1 answer

Golang Chi router not rendering response payload JSON

Go here using Chi renderer for a basic REST service. I have the following structs and functions: type Order struct { OrderId uuid.UUID `json:"orderId",gorm:"type:uuid;primary_key;not null;default gen_random_uuid()"` Quantity …
hotmeatballsoup
  • 385
  • 6
  • 58
  • 136
3
votes
1 answer

How to do unit testing in the case of access log middleware

I have a middleware to log this service access. But I'm confused to do the unit testing several times I surfed googling. I have not found the right way to solve this package accesslog import ( "net/http" "time" …
rsmnarts
  • 185
  • 2
  • 14
3
votes
0 answers

Unit Testing with Go-Chi/Chi

I am trying to write unit tests for my rest endpoints using Go-Chi as my mux. Previously I was using gorilla/mux but moved to Chi because it is easier to maintain as my application grows. With Gorilla/mux, I was able to use "ServeHTTP" to send a…
jmacnc
  • 157
  • 2
  • 7
  • 19
3
votes
1 answer

How to get route inside middleware go-chi

To check authorization i need to know the route inside the authorization middleware. I checked docs from go-chi and did it that way: func Authenticator(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r…
3
votes
1 answer

vue-router in production (serving with Go)

I'd like to separate client and server completely, so I created a vuejs project with vue init webpack my-project. In this project I'm using vue-router for all my routing (this includes special paths, like /user/SOMEID.. This is my routes.js…
fisker
  • 979
  • 4
  • 18
  • 28
2
votes
1 answer

go-chi: accept url path parameter with backslashes in it

I have a path parameter in the format of a distinguished name, and this contains backslash characters. CN=CS.Test Company Hello,OU=World,O=Hello,dnQualifier=m1Ws\+nFSkqy1xBrYUTbxGpzLEcg= I have the path pattern in go-chi server setup…
Arun
  • 57
  • 4
1
2 3 4 5