package main

import (
	"context"
	"fmt"
	"git.nspix.com/golang/micro"
	"math/rand"
	"time"
)

type (
	Request struct {
		Name string
		Age  int
		Co   float64
	}
)

func main() {
	svr := micro.New(
		micro.WithName("git.nspix.com/test", "0.0.01"),
		micro.WithoutRegister(),
		micro.WithHttpDebug(),
		micro.WithStats(),
		micro.WithCli(),
		micro.WithPort(6567),
	)

	svr.Handle("getUserList", func(ctx micro.Context) (err error) {
		var req Request
		if err = ctx.Bind(&req); err != nil {
			return err
		}
		return ctx.Success(req)
	}, func(o *micro.HandleOptions) {
		o.DisableCli = false
	})

	go func() {
		time.AfterFunc(time.Second*5, func() {
			for i := 0; i < 100000; i++ {
				r := rand.Int63n(10000)
				svr.DeferTick(time.Duration(r)*time.Millisecond, func(ctx context.Context) {
					fmt.Println(time.Now().Unix())
				})
			}
		})
	}()

	if err := svr.Run(); err != nil {
		fmt.Println(err)
	}
}
