Skip to content

How do I use the request decoder to access values of the HTTP Request that are not in the header nor the body? #175

Answered by vearutop
ayx-orion asked this question in Q&A
Discussion options

You must be logged in to vote

Currently, the easiest way to access remote addr is to embed request.EmbeddedSetter and then get direct access to *http.Request.

package main

import (
	"context"
	"fmt"
	"log"
	"net/http"

	"github.com/swaggest/openapi-go/openapi31"
	"github.com/swaggest/rest/request"
	"github.com/swaggest/rest/web"
	swgui "github.com/swaggest/swgui/v5cdn"
	"github.com/swaggest/usecase"
)

func main() {
	s := web.NewService(openapi31.NewReflector())

	type inputWithReq struct {
		request.EmbeddedSetter

		Locale string `query:"locale" default:"en-US" pattern:"^[a-z]{2}-[A-Z]{2}$" enum:"ru-RU,en-US"`
		Name   string `path:"name" minLength:"3" default:"Jane"`
	}

	u := usecase.NewInteractor(func(ctx context.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@ayx-orion
Comment options

@ayx-orion
Comment options

Answer selected by ayx-orion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants