Skip to content

How to use with http.ServeFile? #187

Answered by vearutop
gregoryjjb asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, the easiest way to access those would be to embed (or use directly if you don't need extra parameters/headers) request.EmbeddedSetter and response.EmbeddedSetter in your in/out.

Please check an example.
https://github.com/vearutop/photo-blog/blob/v0.0.4/internal/usecase/serve_site_file.go

package usecase

import (
	"context"
	"net/http"
	"path"

	"github.com/swaggest/rest/request"
	"github.com/swaggest/rest/response"
	"github.com/swaggest/usecase"
)

func ServeSiteFile(deps interface{}) usecase.Interactor {
	type fileReq struct {
		File string `path:"file"`
		request.EmbeddedSetter
	}

	u := usecase.NewInteractor(func(ctx context.Context, in fileReq, out *response.EmbeddedSetter) error

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@gregoryjjb
Comment options

Answer selected by gregoryjjb
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