github.com/johnnyeven/libtools@v0.0.0-20191126065708-61829c1adf46/task/test_routers/find_user.go (about)

     1  package test_routers
     2  
     3  import (
     4  	"context"
     5  	"github.com/johnnyeven/libtools/courier/httpx"
     6  	"github.com/johnnyeven/libtools/courier"
     7  	"github.com/sirupsen/logrus"
     8  )
     9  
    10  func init() {
    11  	Router.Register(courier.NewRouter(FindUser{}))
    12  }
    13  
    14  // 查找用户
    15  type FindUser struct {
    16  	httpx.MethodGet
    17  	// 用户ID
    18  	UserID uint64 `name:"userId,string" in:"path"`
    19  }
    20  
    21  func (req FindUser) CronSpec() string {
    22  	return "* * * * * *"
    23  }
    24  
    25  func (req FindUser) Path() string {
    26  	return "/:userId"
    27  }
    28  
    29  func (req FindUser) Output(ctx context.Context) (result interface{}, err error) {
    30  	logrus.Info("johnnyeven")
    31  	return struct {
    32  		UserID   uint64
    33  		UserName string
    34  	}{
    35  		req.UserID,
    36  		"johnnyeven",
    37  	}, nil
    38  }