github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/depends/testutil/httptransporttestutil/server/cmd/app/routes/cookie.go (about)

     1  package routes
     2  
     3  import (
     4  	"context"
     5  	"net/http"
     6  	"time"
     7  
     8  	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport"
     9  	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx"
    10  	"github.com/machinefi/w3bstream/pkg/depends/kit/kit"
    11  )
    12  
    13  var CookieRouter = kit.NewRouter(httptransport.Group("/cookie"))
    14  
    15  func init() {
    16  	RootRouter.Register(CookieRouter)
    17  
    18  	CookieRouter.Register(kit.NewRouter(&Cookie{}))
    19  }
    20  
    21  type Cookie struct {
    22  	httpx.MethodPost
    23  	Token string `name:"token,omitempty" in:"cookie"`
    24  }
    25  
    26  func (req *Cookie) Output(ctx context.Context) (interface{}, error) {
    27  	return httpx.Compose(
    28  		httpx.WrapCookies(&http.Cookie{
    29  			Name:    "token",
    30  			Value:   req.Token,
    31  			Expires: time.Now().Add(24 * time.Hour),
    32  		}),
    33  		httpx.WrapStatusCode(http.StatusNoContent),
    34  	)(nil), nil
    35  }