You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wt-game/point/point.go

47 lines
881 B
Go

package point
import (
"gitea.weitiangame.com/sdk/wt-game/utils/ahttp"
"github.com/go-resty/resty/v2"
"go.uber.org/zap"
"sync"
)
var (
instance *Point
once sync.Once
)
type Point struct {
clientID string
logger *zap.Logger
ahttp *resty.Request
}
// New returns the singleton instance of Point.
func New(clientID string, logger *zap.Logger) *Point {
once.Do(func() {
instance = &Point{
clientID: clientID,
logger: logger,
}
if instance.logger == nil {
var err error
instance.logger, err = zap.NewProduction()
if err != nil {
panic(err)
}
}
instance.ahttp = ahttp.New(nil).SetLog(instance.logger).Client()
})
return instance
}
// Event sends an event to the specified URL.
func (p *Point) Event(data map[string]interface{}) (*resty.Response, error) {
return p.ahttp.SetBody(data).Post("https://e.tapdb.net/v2/event")
}