intimate_view/goserver/main.go

128 lines
2.1 KiB
Go
Raw Normal View History

2020-08-18 11:22:29 +00:00
package main
import (
"database/sql"
"fmt"
"log"
"strconv"
"time"
"github.com/gin-gonic/gin"
_ "github.com/go-sql-driver/mysql"
)
var StoreStreamer *sql.DB
var SqlQuery string = `SELECT
ie.uid,
ie.platform,
ie.user_id,
ie.user_name ,
ie.live_url ,
ie.tags ,
cl.followers ,
cl.views ,
cl.gratuity ,
cl.live_title,
cl.live_start_time ,
cl.live_end_time ,
cl.update_time
From
(
SELECT
*
FROM
intimate_extractor.streamer
WHERE
platform = "twitcasting"
AND operator = 0
AND latest_log_uid is not NULL limit %s,%s) ie
JOIN intimate_extractor.collect_log cl
WHERE
ie.latest_log_uid = cl.log_uid; `
func init() {
db, err := sql.Open("mysql", InitConfig.Database.ExtractorURI)
if err != nil {
panic(err)
}
StoreStreamer = db
}
// ie.uid,
// ie.platform,
// ie.user_id,
// ie.user_name ,
// ie.live_url ,
// ie.tags ,
// cl.followers ,
// cl.views ,
// cl.gratuity ,
// cl.live_title,
// cl.live_start_time ,
// cl.live_end_time ,
// cl.update_time
type ObjectTwistcasting struct {
Uid int64
Platform string
UserId int64
UserName string
LiveUrl string
Tags string
Followers int64
Views int64
Gratuity int64
LiveTitle string
LiveStartTime time.Time
LiveEndTime time.Time
UpdateTime time.Time
}
func TwistcastingQuery(cxt *gin.Context) {
var err error
sstart := cxt.Query("start")
send := cxt.Query("end")
_, err = strconv.Atoi(sstart)
if err != nil {
cxt.Error(err)
}
_, err = strconv.Atoi(send)
if err != nil {
cxt.Error(err)
}
ssql := fmt.Sprintf(SqlQuery, sstart, send)
rows, err := StoreStreamer.Query(ssql)
if err != nil {
log.Panic(err)
}
var ots []*ObjectTwistcasting
for rows.Next() {
ot := &ObjectTwistcasting{}
rows.Scan(
&ot.Uid,
&ot.Platform,
&ot.UserId,
&ot.LiveUrl,
&ot.Tags,
&ot.Followers,
&ot.Views,
&ot.Gratuity,
&ot.LiveTitle,
&ot.LiveStartTime,
&ot.LiveEndTime,
&ot.UpdateTime,
)
ots = append(ots, ot)
}
log.Println(len(ots))
}
func main() {
engine := gin.New() //r := gin.Default() //使用默认中间件
engine.Use(gin.Logger())
engine.GET("twistcasting/data", TwistcastingQuery)
engine.Run(":5500")
}