Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"client.go",
"push.go",
],
importpath = "go-common/app/service/live/third_api/liveBroadcast",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,17 @@
package liveBroadcast
import "go-common/library/net/http/blademaster"
//Client 客户端
type Client struct {
conf *blademaster.ClientConfig
}
func (c *Client) getConf() *blademaster.ClientConfig {
return c.conf
}
//New 创建
func New(c *blademaster.ClientConfig) *Client {
return &Client{conf: c}
}

View File

@@ -0,0 +1,54 @@
package liveBroadcast
import (
"context"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
xhttp "net/http"
"net/url"
"strconv"
"strings"
)
const (
_liveBroadCastURLAddr = "http://live-dm.bilibili.co:80/dm/1/push"
)
// type liveBroadcastReq struct {
// Ensure int64 `json:"ensure"`
// Cid int64 `json:"cid"`
// }
type liveBroadcastResp struct {
Code int64 `json:"ret"`
}
//PushBroadcast 广播
func (c *Client) PushBroadcast(ctx context.Context, cid int64, ensure int64, msg string) (err error) {
if len([]rune(msg)) > 2000 {
return
}
resp := &liveBroadcastResp{}
cli := bm.NewClient(c.getConf())
param := url.Values{}
param.Set("cid", strconv.FormatInt(cid, 10))
param.Set("ensure", strconv.FormatInt(0, 10))
url := _liveBroadCastURLAddr + "?" + param.Encode()
req, err := xhttp.NewRequest(xhttp.MethodPost, url, strings.NewReader(msg))
if err != nil {
log.Error("[BroadCastError]error:%+v=", err)
return err
}
if err := cli.Do(ctx, req, resp); err != nil {
log.Error("[BroadCastError]error:%+v=", err)
return err
}
if resp.Code != 1 {
log.Error("BroadCastError] errorcode:%d", resp.Code)
}
return
}