middleware.Responder を実装してCookieをsetする.

func Handler(params foo.Requestparams) middleware.Responder {
    ...
    何らかの処理
    ...

    return NewSetCookieResponder(foo.NewSetCookieOK().WithPayload(&models.SetCookieResponse{}))
}


type SetCookieResponder struct {
	responder middleware.Responder
}

func  NewSetCookieResponder(responder middleware.Responder) *SetCookieResponder {
	return &SetCookieResponder{
		responder: responder,
	}
}

func (l *SetCookieResponder) WriteResponse(rw http.ResponseWriter, p runtime.Producer) {
	http.SetCookie(rw, &http.Cookie{
		Name:     "some token name",
		Value:    "hogehogehoge",
		Domain:   "localhost",
		Path:     "/",
		HttpOnly: true,
		Secure:   true,
		Expires:  time.Now().Add(7 * 24 * time.Hour),
		SameSite: http.SameSiteStrictMode,
	})
	l.responder.WriteResponse(rw, p)
}