- update amap

- update baidu
- update qq
master
李光春 1 year ago
parent fcdd3f0c6f
commit 733ac2012b

@ -8,7 +8,7 @@ require (
github.com/allegro/bigcache/v3 v3.1.0
github.com/baidubce/bce-sdk-go v0.9.146
github.com/basgys/goxml2json v1.1.0
github.com/bytedance/sonic v1.8.6
github.com/bytedance/sonic v1.8.7
github.com/gin-gonic/gin v1.9.0
github.com/go-co-op/gocron v1.19.0
github.com/go-playground/locales v0.14.1

@ -46,8 +46,8 @@ github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngE
github.com/bsm/ginkgo/v2 v2.7.0 h1:ItPMPH90RbmZJt5GtkcNvIRuGEdwlBItdNVoyzaNQao=
github.com/bsm/gomega v1.26.0 h1:LhQm+AFcgV2M0WyKroMASzAzCAJVpAxQXv4SaI9a69Y=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
github.com/bytedance/sonic v1.8.6 h1:aUgO9S8gvdN6SyW2EhIpAw5E4ChworywIEndZCkCVXk=
github.com/bytedance/sonic v1.8.6/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
github.com/bytedance/sonic v1.8.7 h1:d3sry5vGgVq/OpgozRUNP6xBsSo0mtNdwliApw+SAMQ=
github.com/bytedance/sonic v1.8.7/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=

@ -1,5 +1,5 @@
package go_library
func Version() string {
return "1.0.125"
return "1.0.126"
}

@ -0,0 +1,12 @@
package amap
import "github.com/dtapps/go-library/utils/golog"
// ConfigApiClientFun 日志配置
func (c *Client) ConfigApiClientFun(apiClientFun golog.ApiClientFun) {
apiClient := apiClientFun()
if apiClient != nil {
c.log.client = apiClient
c.log.status = true
}
}

@ -3,35 +3,31 @@ package baidu
import (
"github.com/dtapps/go-library/utils/golog"
"github.com/dtapps/go-library/utils/gorequest"
"gorm.io/gorm"
)
type ConfigClient struct {
PgsqlDb *gorm.DB // 日志数据库
// ClientConfig 实例配置
type ClientConfig struct {
Ak string
}
type Client struct {
client *gorequest.App // 请求客户端
log *golog.ApiClient // 日志服务
config *ConfigClient // 配置
requestClient *gorequest.App // 请求服务
config struct {
ak string
}
log struct {
status bool // 状态
client *golog.ApiClient // 日志服务
}
}
func NewClient(config *ConfigClient) (*Client, error) {
// NewClient 创建实例化
func NewClient(config *ClientConfig) (*Client, error) {
var err error
c := &Client{config: config}
c := &Client{}
c.client = gorequest.NewHttp()
c.config.ak = config.Ak
if c.config.PgsqlDb != nil {
c.log, err = golog.NewApiClient(
golog.WithGormClient(c.config.PgsqlDb),
golog.WithTableName(logTable),
)
if err != nil {
return nil, err
}
}
c.requestClient = gorequest.NewHttp()
return c, nil
}

@ -0,0 +1,12 @@
package baidu
import "github.com/dtapps/go-library/utils/golog"
// ConfigApiClientFun 日志配置
func (c *Client) ConfigApiClientFun(apiClientFun golog.ApiClientFun) {
apiClient := apiClientFun()
if apiClient != nil {
c.log.client = apiClient
c.log.status = true
}
}

@ -1,5 +1,9 @@
package baidu
const (
apiUrl = "https://api.map.baidu.com"
)
const (
logTable = "baidu"
)

@ -1,33 +0,0 @@
package baidu
import (
"github.com/dtapps/go-library/utils/gojson"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
)
type ExpressResponse struct{}
type ExpressResult struct {
Result ExpressResponse // 结果
Body []byte // 内容
Http gorequest.Response // 请求
Err error // 错误
}
func newExpressResult(result ExpressResponse, body []byte, http gorequest.Response, err error) *ExpressResult {
return &ExpressResult{Result: result, Body: body, Http: http, Err: err}
}
// Express ipv1
// https://www.cloudflare.com/ips-v4
func (c *Client) Express() *ExpressResult {
// 参数
params := gorequest.NewParams()
// 请求
request, err := c.request("https://m.baidu.com/s?word=快递查询&ts={$ts}&t_kt=0&ie=utf-8&rsv_iqid=&rsv_t=&sa=&rsv_pq=&rsv_sug4=&tj=1&inputT={$input}&sugid=&ss=", params, http.MethodPost)
// 定义
var response ExpressResponse
err = gojson.Unmarshal(request.ResponseBody, &response)
return newExpressResult(response, request.ResponseBody, request, err)
}

@ -0,0 +1,11 @@
package baidu
import "github.com/dtapps/go-library/utils/golog"
func (c *Client) GetAk() string {
return c.config.ak
}
func (c *Client) GetLog() *golog.ApiClient {
return c.log.client
}

@ -0,0 +1,57 @@
package baidu
import (
"context"
"github.com/dtapps/go-library/utils/gojson"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
)
type LocationIpResponse struct {
Address string `json:"address"` // 详细地址信息
Content struct {
AddressDetail struct {
Province string `json:"province"` // 省份
City string `json:"city"` // 城市
District string `json:"district"`
Street string `json:"street"`
StreetNumber string `json:"street_number"`
CityCode int `json:"city_code"` // 百度城市代码
Adcode string `json:"adcode"`
} `json:"address_detail"`
Address string `json:"address"` // 简要地址信息
Point struct {
X string `json:"x"` // 当前城市中心点经度
Y string `json:"y"` // 当前城市中心点纬度
} `json:"point"`
} `json:"content"`
Status int `json:"status"`
}
type LocationIpResult struct {
Result LocationIpResponse // 结果
Body []byte // 内容
Http gorequest.Response // 请求
}
func newLocationIpResult(result LocationIpResponse, body []byte, http gorequest.Response) *LocationIpResult {
return &LocationIpResult{Result: result, Body: body, Http: http}
}
// LocationIp 普通IP定位
// https://lbsyun.baidu.com/index.php?title=webapi/ip-api
func (c *Client) LocationIp(ctx context.Context, ip string, notMustParams ...gorequest.Params) (*LocationIpResult, error) {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
params.Set("ak", c.GetAk())
params.Set("ip", ip)
// 请求
request, err := c.request(ctx, apiUrl+"/location/ip", params, http.MethodGet)
if err != nil {
return newLocationIpResult(LocationIpResponse{}, request.ResponseBody, request), err
}
// 定义
var response LocationIpResponse
err = gojson.Unmarshal(request.ResponseBody, &response)
return newLocationIpResult(response, request.ResponseBody, request), err
}

@ -1,11 +1,15 @@
package baidu
import "github.com/dtapps/go-library/utils/gorequest"
import (
"context"
"github.com/dtapps/go-library"
"github.com/dtapps/go-library/utils/gorequest"
)
func (c *Client) request(url string, params map[string]interface{}, method string) (gorequest.Response, error) {
func (c *Client) request(ctx context.Context, url string, params map[string]interface{}, method string) (gorequest.Response, error) {
// 创建请求
client := c.client
client := c.requestClient
// 设置请求地址
client.SetUri(url)
@ -19,15 +23,18 @@ func (c *Client) request(url string, params map[string]interface{}, method strin
// 设置参数
client.SetParams(params)
// 传入SDk版本
client.AfferentSdkUserVersion(go_library.Version())
// 发起请求
request, err := client.Request()
request, err := client.Request(ctx)
if err != nil {
return gorequest.Response{}, err
}
// 日志
if c.config.PgsqlDb != nil {
go c.log.GormMiddleware(request)
// 记录日志
if c.log.status {
go c.log.client.Middleware(ctx, request, go_library.Version())
}
return request, err

@ -0,0 +1,72 @@
package baidu
import (
"context"
"github.com/dtapps/go-library/utils/gojson"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
)
type WeatherResponse struct {
Status int `json:"status"`
Result struct {
Location struct {
Country string `json:"country"`
Province string `json:"province"`
City string `json:"city"`
Name string `json:"name"`
Id string `json:"id"`
} `json:"location"`
Now struct {
Text string `json:"text"`
Temp int `json:"temp"`
FeelsLike int `json:"feels_like"`
Rh int `json:"rh"`
WindClass string `json:"wind_class"`
WindDir string `json:"wind_dir"`
Uptime string `json:"uptime"`
} `json:"now"`
Forecasts []struct {
TextDay string `json:"text_day"`
TextNight string `json:"text_night"`
High int `json:"high"`
Low int `json:"low"`
WcDay string `json:"wc_day"`
WdDay string `json:"wd_day"`
WcNight string `json:"wc_night"`
WdNight string `json:"wd_night"`
Date string `json:"date"`
Week string `json:"week"`
} `json:"forecasts"`
} `json:"result"`
Message string `json:"message"`
}
type WeatherResult struct {
Result WeatherResponse // 结果
Body []byte // 内容
Http gorequest.Response // 请求
}
func newWeatherResult(result WeatherResponse, body []byte, http gorequest.Response) *WeatherResult {
return &WeatherResult{Result: result, Body: body, Http: http}
}
// Weather 国内天气查询服务
// https://lbsyun.baidu.com/index.php?title=webapi/weather
func (c *Client) Weather(ctx context.Context, districtId string, notMustParams ...gorequest.Params) (*WeatherResult, error) {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
params.Set("ak", c.GetAk())
params.Set("district_id", districtId)
params.Set("output", "json")
// 请求
request, err := c.request(ctx, apiUrl+"/weather/v1/", params, http.MethodGet)
if err != nil {
return newWeatherResult(WeatherResponse{}, request.ResponseBody, request), err
}
// 定义
var response WeatherResponse
err = gojson.Unmarshal(request.ResponseBody, &response)
return newWeatherResult(response, request.ResponseBody, request), err
}

@ -0,0 +1,12 @@
package qq
import "github.com/dtapps/go-library/utils/golog"
// ConfigApiClientFun 日志配置
func (c *Client) ConfigApiClientFun(apiClientFun golog.ApiClientFun) {
apiClient := apiClientFun()
if apiClient != nil {
c.log.client = apiClient
c.log.status = true
}
}

@ -679,12 +679,38 @@ func (self *_Compiler) compilePtr(p *_Program, sp int, et reflect.Type) {
/* dereference all the way down */
for et.Kind() == reflect.Ptr {
if et.Implements(jsonUnmarshalerType) {
p.rtt(_OP_unmarshal_p, et)
return
}
if et.Implements(encodingTextUnmarshalerType) {
p.add(_OP_lspace)
self.compileUnmarshalTextPtr(p, et)
return
}
et = et.Elem()
p.rtt(_OP_deref, et)
}
/* compile the element type */
self.compileOne(p, sp + 1, et)
/* check for recursive nesting */
ok := self.tab[et]
if ok {
p.rtt(_OP_recurse, et)
return
}
/* enter the recursion */
p.add(_OP_lspace)
self.tab[et] = true
/* not inline the pointer type
* recursing the defined pointer type's elem will casue issue379.
*/
self.compileOps(p, sp, et)
delete(self.tab, et)
j := p.pc()
p.add(_OP_goto)
p.pin(i)

@ -17,6 +17,7 @@
package decoder
import (
`unsafe`
`encoding/json`
`reflect`
`runtime`
@ -127,8 +128,17 @@ func (self *Decoder) Decode(val interface{}) error {
return &json.InvalidUnmarshalError{Type: vv.Type.Pack()}
}
etp := rt.PtrElem(vv.Type)
/* check the defined pointer type for issue 379 */
if vv.Type.IsNamed() {
newp := vp
etp = vv.Type
vp = unsafe.Pointer(&newp)
}
/* create a new stack, and call the decoder */
sb, etp := newStack(), rt.PtrElem(vv.Type)
sb := newStack()
nb, err := decodeTypedPointer(self.s, self.i, etp, vp, sb, self.f)
/* return the stack back */
self.i = nb

@ -514,7 +514,8 @@ func (self *_Assembler) call_marshaler(fn obj.Addr, it *rt.GoType, vt reflect.Ty
switch vt.Kind() {
case reflect.Interface : self.call_marshaler_i(fn, it)
case reflect.Ptr, reflect.Map: self.call_marshaler_v(fn, it, vt, true)
default : self.call_marshaler_v(fn, it, vt, false)
// struct/array of 1 direct iface type can be direct
default : self.call_marshaler_v(fn, it, vt, !rt.UnpackType(vt).Indirect())
}
}

@ -539,7 +539,8 @@ func (self *_Assembler) call_marshaler(fn obj.Addr, it *rt.GoType, vt reflect.Ty
switch vt.Kind() {
case reflect.Interface : self.call_marshaler_i(fn, it)
case reflect.Ptr, reflect.Map : self.call_marshaler_v(fn, it, vt, true)
default : self.call_marshaler_v(fn, it, vt, false)
// struct/array of 1 direct iface type can be direct
default : self.call_marshaler_v(fn, it, vt, !rt.UnpackType(vt).Indirect())
}
}

@ -22,14 +22,23 @@ import (
)
var (
reflectRtypeItab = findReflectRtypeItab()
reflectRtypeItab = findReflectRtypeItab()
)
// GoType.KindFlags const
const (
F_direct = 1 << 5
F_kind_mask = (1 << 5) - 1
)
// GoType.Flags const
const (
tflagUncommon uint8 = 1 << 0
tflagExtraStar uint8 = 1 << 1
tflagNamed uint8 = 1 << 2
tflagRegularMemory uint8 = 1 << 3
)
type GoType struct {
Size uintptr
PtrData uintptr
@ -44,6 +53,10 @@ type GoType struct {
PtrToSelf int32
}
func (self *GoType) IsNamed() bool {
return (self.Flags & tflagNamed) != 0
}
func (self *GoType) Kind() reflect.Kind {
return reflect.Kind(self.KindFlags & F_kind_mask)
}

@ -24,7 +24,7 @@ github.com/baidubce/bce-sdk-go/util/log
github.com/basgys/goxml2json
# github.com/bitly/go-simplejson v0.5.0
## explicit
# github.com/bytedance/sonic v1.8.6
# github.com/bytedance/sonic v1.8.7
## explicit; go 1.15
github.com/bytedance/sonic
github.com/bytedance/sonic/ast

Loading…
Cancel
Save