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,48 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"authority.go",
"http.go",
"http_base.go",
"mcn.go",
"recommend.go",
"statistics.go",
"upload.go",
],
importpath = "go-common/app/admin/main/mcn/server/http",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/admin/main/mcn/conf:go_default_library",
"//app/admin/main/mcn/model:go_default_library",
"//app/admin/main/mcn/service:go_default_library",
"//library/ecode:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/net/http/blademaster/binding:go_default_library",
"//library/net/http/blademaster/middleware/permit:go_default_library",
"//library/net/http/blademaster/render:go_default_library",
"//vendor/github.com/pkg/errors: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,25 @@
package http
import (
"net/http"
"go-common/library/ecode"
bm "go-common/library/net/http/blademaster"
)
// check username and dashboard sessionid
func checkCookie(c *bm.Context) (username, sid string, err error) {
var r = c.Request
var name *http.Cookie
if name, err = r.Cookie("username"); err == nil {
username = name.Value
}
var session *http.Cookie
if session, err = r.Cookie("_AJSESSIONID"); err == nil {
sid = session.Value
}
if username == "" || sid == "" {
err = ecode.Unauthorized
}
return
}

View File

@@ -0,0 +1,95 @@
package http
import (
"net/http"
"go-common/app/admin/main/mcn/conf"
"go-common/app/admin/main/mcn/service"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
"go-common/library/net/http/blademaster/middleware/permit"
)
var (
srv *service.Service
authSvc *permit.Permit
)
// Init init
func Init(c *conf.Config) {
initService(c)
engine := bm.DefaultServer(c.BM)
route(engine)
if err := engine.Start(); err != nil {
log.Error("bm Start error(%v)", err)
panic(err)
}
}
// initService init service
func initService(c *conf.Config) {
srv = service.New(c)
authSvc = permit.New(c.Auth)
}
func route(e *bm.Engine) {
e.Ping(ping)
e.Register(register)
g := e.Group("/allowance/api/x/admin/mcn") // authSvc.Verify() manager use
{
// mcn account .
g.POST("/sign/upload", upload)
g.POST("/sign/entry", mcnSignEntry)
g.GET("/sign/list", mcnSignList)
g.POST("/sign/op", mcnSignOP)
g.GET("/sign/up/list", mcnUPReviewList)
g.POST("/sign/up/op", mcnUPOP)
g.POST("/sign/permit/op", mcnPermitOP)
g.GET("/sign/up/permit/list", mcnUPPermitList)
g.POST("/sign/up/permit/op", mcnUPPermitOP)
// mcn list.
g.GET("/list", mcnList)
// g.POST("/pay/add", mcnPayAdd)
g.POST("/pay/edit", mcnPayEdit)
g.POST("/pay/state/edit", mcnPayStateEdit)
g.POST("/state/edit", mcnStateEdit)
g.POST("/renewal", mcnRenewal)
// up list
g.GET("/info", mcnInfo)
g.GET("/up/list", mcnUPList)
g.POST("/up/state/edit", mcnUPStatEdit)
// 二期
g.GET("/cheat/list", mcnCheatList)
g.GET("/cheat/up/list", mcnCheatUPList)
g.GET("/import/up/info", mcnImportUPInfo)
g.POST("/import/up/reward/sign", mcnImportUPRewardSign)
g.GET("/increase/list", mcnIncreaseList)
// up fans rank
g.GET("/rank/archive/likes", arcTopDataStatistics)
// up fans analyze
g.GET("/up/fans/analyze", mcnFansAnalyze)
// mcn total statistics
g.GET("/total/statistics", mcnsTotalDatas)
// up recommend
g.GET("/recommend/list", recommendList)
g.POST("/recommend/op", recommendOP)
g.POST("/recommend/add", recommendAdd)
}
}
func ping(c *bm.Context) {
if err := srv.Ping(c); err != nil {
log.Error("ping error(%v)", err)
c.AbortWithStatus(http.StatusServiceUnavailable)
}
}
func register(c *bm.Context) {
c.JSON(map[string]interface{}{}, nil)
}

View File

@@ -0,0 +1,187 @@
package http
import (
"bytes"
"context"
"encoding/csv"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"reflect"
"go-common/app/admin/main/mcn/model"
"go-common/library/ecode"
"go-common/library/log"
"go-common/library/net/http/blademaster"
"go-common/library/net/http/blademaster/binding"
"go-common/library/net/http/blademaster/render"
"github.com/pkg/errors"
)
func bmHTTPErrorWithMsg(c *blademaster.Context, err error) {
if c.IsAborted() {
return
}
c.Error = err
bcode, ok := errors.Cause(err).(ecode.Codes)
var msg string
if !ok {
msg = err.Error()
bcode = ecode.String(err.Error())
} else {
msg = bcode.Message()
}
c.Render(http.StatusOK, render.JSON{
Code: bcode.Code(),
Message: msg,
Data: nil,
})
}
func checkCookieFun(c *blademaster.Context) (err error) {
_, _, err = checkCookie(c)
return
}
// service的函数原型
type serviceFunc func(context context.Context, arg interface{}) (res interface{}, err error)
// response writer
type responseWriter func(c *blademaster.Context, arg interface{}, res interface{}, err error)
type argParser func(c *blademaster.Context, arg interface{}) (err error)
func argGetParser(c *blademaster.Context, arg interface{}) (err error) {
err = c.Bind(arg)
return
}
// argPostJSONParser .
func argPostJSONParser(c *blademaster.Context, arg interface{}) (err error) {
respBody, _ := ioutil.ReadAll(c.Request.Body)
if err = json.Unmarshal(respBody, arg); err != nil {
log.Error("json unmarshal fail, err=%v", err)
return
}
if err = binding.Validator.ValidateStruct(arg); err != nil {
log.Error("binding.Validator.ValidateStruct(%+v) error(%+v)", arg, err)
}
return
}
func jsonWriter(c *blademaster.Context, arg interface{}, res interface{}, err error) {
c.JSON(res, err)
}
func csvWriter(c *blademaster.Context, arg interface{}, res interface{}, err error) {
formater, ok := res.(model.CsvFormatter)
if !ok {
log.Error("res cannot convert CsvFommater, res type=%s", reflect.TypeOf(res).Name())
c.String(ecode.ServerErr.Code(), "res cannot convert CsvFommater")
return
}
c.Writer.Header().Set("Content-Type", "application/csv")
c.Writer.Header().Set("Content-Disposition", fmt.Sprintf("attachment;filename=\"%s\"", formater.GetFileName()))
var buf = &bytes.Buffer{}
var csvWriter = csv.NewWriter(buf)
formater.ToCsv(csvWriter)
csvWriter.Flush()
c.Writer.Write(buf.Bytes())
}
func decideWriter(c *blademaster.Context, arg interface{}, res interface{}, err error) {
var writer responseWriter
var decider, ok = arg.(model.ExportArgInterface)
if ok {
switch decider.ExportFormat() {
case model.ResponeModelJSON:
writer = jsonWriter
case model.ResponeModelCSV:
writer = csvWriter
}
}
if writer != nil {
writer(c, arg, res, err)
} else {
jsonWriter(c, arg, res, err)
}
}
func httpGenerateFunc(arg interface{}, sfunc serviceFunc, description string, parser argParser, writer responseWriter, preFuncs ...func(*blademaster.Context) error) func(*blademaster.Context) {
return func(c *blademaster.Context) {
var res interface{}
var err error
exitswitch:
switch {
default:
for _, f := range preFuncs {
err = f(c)
if err != nil {
break exitswitch
}
}
if err = parser(c, arg); err != nil {
log.Error("%s, request argument bind fail, err=%v", description, err)
err = ecode.RequestErr
break
}
var scoreRes, e = sfunc(c, arg)
err = e
if e != nil {
log.Error("%s query fail, req=%+v, err=%+v", description, arg, err)
break
}
log.Info("%s query ok, req=%+v, result=%+v", description, arg, scoreRes)
res = scoreRes
}
if err != nil {
bmHTTPErrorWithMsg(c, err)
} else {
writer(c, arg, res, err)
}
}
}
func httpPostJSONCookie(arg interface{}, sfunc serviceFunc, description string, preFuncs ...func(*blademaster.Context) error) func(*blademaster.Context) {
preFuncs = append(preFuncs, checkCookieFun)
return httpGenerateFunc(arg, sfunc, description, argPostJSONParser, jsonWriter, preFuncs...)
}
// func httpPostFormCookie(arg interface{}, sfunc serviceFunc, description string, preFuncs ...func(*blademaster.Context) error) func(*blademaster.Context) {
// preFuncs = append(preFuncs, checkCookieFun)
// return httpGenerateFunc(arg, sfunc, description, argGetParser, jsonWriter, preFuncs...)
// }
func httpGetFunCheckCookie(arg interface{}, sfunc serviceFunc, description string, preFuncs ...func(*blademaster.Context) error) func(*blademaster.Context) {
preFuncs = append(preFuncs, checkCookieFun)
return httpGenerateFunc(arg, sfunc, description, argGetParser, jsonWriter, preFuncs...)
}
// func httpGetFunc(arg interface{}, sfunc serviceFunc, description string) func(*blademaster.Context) {
// return httpGetFuncWithWriter(arg, sfunc, description, jsonWriter)
// }
func httpGetFuncWithWriter(arg interface{}, sfunc serviceFunc, description string, writer responseWriter) func(*blademaster.Context) {
return httpGenerateFunc(arg, sfunc, description, argGetParser, writer)
}
func httpGetWriterByExport(arg interface{}, sfunc serviceFunc, description string) func(*blademaster.Context) {
return httpGetFuncWithWriter(arg, sfunc, description, decideWriter)
}
//func offlineactivityAdd(c *blademaster.Context) {
// httpPostFunCheckCookie(
// new(offlineactivity.AddActivityArg),
// func(context context.Context, arg interface{}) (res interface{}, err error) {
// return svr.AddOfflineActivity(context, arg.(*offlineactivity.AddActivityArg))
// },
// "offlineactivityAdd")(c)
//}

View File

@@ -0,0 +1,328 @@
package http
import (
"context"
"net/http"
"strconv"
"go-common/app/admin/main/mcn/model"
"go-common/library/net/http/blademaster"
)
func mcnSignEntry(c *blademaster.Context) {
httpPostJSONCookie(
new(model.MCNSignEntryReq),
func(cont context.Context, arg interface{}) (res interface{}, err error) {
var uids, name *http.Cookie
args := arg.(*model.MCNSignEntryReq)
if name, err = c.Request.Cookie("username"); err == nil {
args.UserName = name.Value
}
if uids, err = c.Request.Cookie("uid"); err == nil {
if args.UID, err = strconv.ParseInt(uids.Value, 10, 64); err != nil {
return
}
}
return nil, srv.McnSignEntry(cont, arg.(*model.MCNSignEntryReq))
},
"mcnSignEntry")(c)
}
func mcnSignList(c *blademaster.Context) {
httpGetFunCheckCookie(
new(model.MCNSignStateReq),
func(cont context.Context, arg interface{}) (res interface{}, err error) {
return srv.McnSignList(cont, arg.(*model.MCNSignStateReq))
},
"mcnSignList")(c)
}
func mcnSignOP(c *blademaster.Context) {
httpPostJSONCookie(
new(model.MCNSignStateOpReq),
func(cont context.Context, arg interface{}) (res interface{}, err error) {
var uids, name *http.Cookie
args := arg.(*model.MCNSignStateOpReq)
if name, err = c.Request.Cookie("username"); err == nil {
args.UserName = name.Value
}
if uids, err = c.Request.Cookie("uid"); err == nil {
if args.UID, err = strconv.ParseInt(uids.Value, 10, 64); err != nil {
return
}
}
return nil, srv.McnSignOP(cont, arg.(*model.MCNSignStateOpReq))
},
"mcnSignOP")(c)
}
func mcnUPReviewList(c *blademaster.Context) {
httpGetFunCheckCookie(
new(model.MCNUPStateReq),
func(cont context.Context, arg interface{}) (res interface{}, err error) {
return srv.McnUPReviewList(cont, arg.(*model.MCNUPStateReq))
},
"mcnUPReviewList")(c)
}
func mcnUPOP(c *blademaster.Context) {
httpPostJSONCookie(
new(model.MCNUPStateOpReq),
func(cont context.Context, arg interface{}) (res interface{}, err error) {
var uids, name *http.Cookie
args := arg.(*model.MCNUPStateOpReq)
if name, err = c.Request.Cookie("username"); err == nil {
args.UserName = name.Value
}
if uids, err = c.Request.Cookie("uid"); err == nil {
if args.UID, err = strconv.ParseInt(uids.Value, 10, 64); err != nil {
return
}
}
return nil, srv.McnUPOP(cont, arg.(*model.MCNUPStateOpReq))
},
"mcnUPOP")(c)
}
func mcnPermitOP(c *blademaster.Context) {
httpPostJSONCookie(
new(model.MCNSignPermissionReq),
func(cont context.Context, arg interface{}) (res interface{}, err error) {
var uids, name *http.Cookie
args := arg.(*model.MCNSignPermissionReq)
if name, err = c.Request.Cookie("username"); err == nil {
args.UserName = name.Value
}
if uids, err = c.Request.Cookie("uid"); err == nil {
if args.UID, err = strconv.ParseInt(uids.Value, 10, 64); err != nil {
return
}
}
return nil, srv.McnPermitOP(cont, arg.(*model.MCNSignPermissionReq))
},
"McnPermitOP")(c)
}
func mcnUPPermitList(c *blademaster.Context) {
httpGetFunCheckCookie(
new(model.MCNUPPermitStateReq),
func(cont context.Context, arg interface{}) (res interface{}, err error) {
return srv.McnUPPermitList(cont, arg.(*model.MCNUPPermitStateReq))
},
"McnUPPermitList")(c)
}
func mcnUPPermitOP(c *blademaster.Context) {
httpPostJSONCookie(
new(model.MCNUPPermitOPReq),
func(cont context.Context, arg interface{}) (res interface{}, err error) {
var uids, name *http.Cookie
args := arg.(*model.MCNUPPermitOPReq)
if name, err = c.Request.Cookie("username"); err == nil {
args.UserName = name.Value
}
if uids, err = c.Request.Cookie("uid"); err == nil {
if args.UID, err = strconv.ParseInt(uids.Value, 10, 64); err != nil {
return
}
}
return nil, srv.McnUPPermitOP(cont, arg.(*model.MCNUPPermitOPReq))
},
"McnUPPermitOP")(c)
}
func mcnList(c *blademaster.Context) {
httpGetWriterByExport(
new(model.MCNListReq),
func(cont context.Context, arg interface{}) (res interface{}, err error) {
return srv.MCNList(cont, arg.(*model.MCNListReq))
},
"mcnList")(c)
}
func mcnPayEdit(c *blademaster.Context) {
httpPostJSONCookie(
new(model.MCNPayEditReq),
func(cont context.Context, arg interface{}) (res interface{}, err error) {
var uids, name *http.Cookie
args := arg.(*model.MCNPayEditReq)
if name, err = c.Request.Cookie("username"); err == nil {
args.UserName = name.Value
}
if uids, err = c.Request.Cookie("uid"); err == nil {
if args.UID, err = strconv.ParseInt(uids.Value, 10, 64); err != nil {
return
}
}
return nil, srv.MCNPayEdit(cont, arg.(*model.MCNPayEditReq))
},
"mcnPayEdit")(c)
}
// func mcnPayEdit(c *blademaster.Context) {
// httpPostFunCheckCookie(
// new(model.MCNPayEditReq),
// func(cont context.Context, arg interface{}) (res interface{}, err error) {
// var uids,name *http.Cookie
// args := arg.(*model.MCNPayEditReq)
// if name, err = c.Request.Cookie("username"); err == nil {
// args.UserName = name.Value
// }
// if uids, err = c.Request.Cookie("uid"); err == nil {
// if args.UID, err = strconv.ParseInt(uids.Value, 10, 64); err != nil {
// return
// }
// }
// return nil, srv.MCNPayEdit(cont, arg.(*model.MCNPayEditReq))
// },
// "mcnPayEdit")(c)
// }
func mcnPayStateEdit(c *blademaster.Context) {
httpPostJSONCookie(
new(model.MCNPayStateEditReq),
func(cont context.Context, arg interface{}) (res interface{}, err error) {
var uids, name *http.Cookie
args := arg.(*model.MCNPayStateEditReq)
if name, err = c.Request.Cookie("username"); err == nil {
args.UserName = name.Value
}
if uids, err = c.Request.Cookie("uid"); err == nil {
if args.UID, err = strconv.ParseInt(uids.Value, 10, 64); err != nil {
return
}
}
return nil, srv.MCNPayStateEdit(cont, arg.(*model.MCNPayStateEditReq))
},
"mcnPayStateEdit")(c)
}
func mcnStateEdit(c *blademaster.Context) {
httpPostJSONCookie(
new(model.MCNStateEditReq),
func(cont context.Context, arg interface{}) (res interface{}, err error) {
var uids, name *http.Cookie
args := arg.(*model.MCNStateEditReq)
if name, err = c.Request.Cookie("username"); err == nil {
args.UserName = name.Value
}
if uids, err = c.Request.Cookie("uid"); err == nil {
if args.UID, err = strconv.ParseInt(uids.Value, 10, 64); err != nil {
return
}
}
return nil, srv.MCNStateEdit(cont, arg.(*model.MCNStateEditReq))
},
"mcnStateEdit")(c)
}
func mcnRenewal(c *blademaster.Context) {
httpPostJSONCookie(
new(model.MCNRenewalReq),
func(cont context.Context, arg interface{}) (res interface{}, err error) {
var uids, name *http.Cookie
args := arg.(*model.MCNRenewalReq)
if name, err = c.Request.Cookie("username"); err == nil {
args.UserName = name.Value
}
if uids, err = c.Request.Cookie("uid"); err == nil {
if args.UID, err = strconv.ParseInt(uids.Value, 10, 64); err != nil {
return
}
}
return nil, srv.MCNRenewal(cont, arg.(*model.MCNRenewalReq))
},
"mcnRenewal")(c)
}
func mcnInfo(c *blademaster.Context) {
httpGetFunCheckCookie(
new(model.MCNInfoReq),
func(cont context.Context, arg interface{}) (res interface{}, err error) {
return srv.MCNInfo(cont, arg.(*model.MCNInfoReq))
},
"mcnInfo")(c)
}
func mcnUPList(c *blademaster.Context) {
httpGetWriterByExport(
new(model.MCNUPListReq),
func(cont context.Context, arg interface{}) (res interface{}, err error) {
return srv.MCNUPList(cont, arg.(*model.MCNUPListReq))
},
"mcnUPList")(c)
}
func mcnUPStatEdit(c *blademaster.Context) {
httpPostJSONCookie(
new(model.MCNUPStateEditReq),
func(cont context.Context, arg interface{}) (res interface{}, err error) {
var uids, name *http.Cookie
args := arg.(*model.MCNUPStateEditReq)
if name, err = c.Request.Cookie("username"); err == nil {
args.UserName = name.Value
}
if uids, err = c.Request.Cookie("uid"); err == nil {
if args.UID, err = strconv.ParseInt(uids.Value, 10, 64); err != nil {
return
}
}
return nil, srv.MCNUPStateEdit(cont, arg.(*model.MCNUPStateEditReq))
},
"mcnUPStatEdit")(c)
}
func mcnCheatList(c *blademaster.Context) {
httpGetFunCheckCookie(
new(model.MCNCheatListReq),
func(cont context.Context, arg interface{}) (res interface{}, err error) {
return srv.MCNCheatList(cont, arg.(*model.MCNCheatListReq))
},
"mcnCheatList")(c)
}
func mcnCheatUPList(c *blademaster.Context) {
httpGetFunCheckCookie(
new(model.MCNCheatUPListReq),
func(cont context.Context, arg interface{}) (res interface{}, err error) {
return srv.MCNCheatUPList(cont, arg.(*model.MCNCheatUPListReq))
},
"mcnCheatUPList")(c)
}
func mcnImportUPInfo(c *blademaster.Context) {
httpGetFunCheckCookie(
new(model.MCNImportUPInfoReq),
func(cont context.Context, arg interface{}) (res interface{}, err error) {
return srv.MCNImportUPInfo(cont, arg.(*model.MCNImportUPInfoReq))
},
"mcnImportUPInfo")(c)
}
func mcnImportUPRewardSign(c *blademaster.Context) {
httpPostJSONCookie(
new(model.MCNImportUPRewardSignReq),
func(cont context.Context, arg interface{}) (res interface{}, err error) {
var uids, name *http.Cookie
args := arg.(*model.MCNImportUPRewardSignReq)
if name, err = c.Request.Cookie("username"); err == nil {
args.UserName = name.Value
}
if uids, err = c.Request.Cookie("uid"); err == nil {
if args.UID, err = strconv.ParseInt(uids.Value, 10, 64); err != nil {
return
}
}
return nil, srv.MCNImportUPRewardSign(cont, arg.(*model.MCNImportUPRewardSignReq))
},
"mcnImportUPRewardSign")(c)
}
func mcnIncreaseList(c *blademaster.Context) {
httpGetFunCheckCookie(
new(model.MCNIncreaseListReq),
func(cont context.Context, arg interface{}) (res interface{}, err error) {
return srv.MCNIncreaseList(cont, arg.(*model.MCNIncreaseListReq))
},
"mcnIncreaseList")(c)
}

View File

@@ -0,0 +1,57 @@
package http
import (
"context"
"net/http"
"strconv"
"go-common/app/admin/main/mcn/model"
"go-common/library/net/http/blademaster"
)
func recommendAdd(c *blademaster.Context) {
httpPostJSONCookie(
new(model.RecommendUpReq),
func(cont context.Context, arg interface{}) (res interface{}, err error) {
var uids, name *http.Cookie
args := arg.(*model.RecommendUpReq)
if name, err = c.Request.Cookie("username"); err == nil {
args.UserName = name.Value
}
if uids, err = c.Request.Cookie("uid"); err == nil {
if args.UID, err = strconv.ParseInt(uids.Value, 10, 64); err != nil {
return
}
}
return nil, srv.RecommendAdd(cont, arg.(*model.RecommendUpReq))
},
"recommendAdd")(c)
}
func recommendOP(c *blademaster.Context) {
httpPostJSONCookie(
new(model.RecommendStateOpReq),
func(cont context.Context, arg interface{}) (res interface{}, err error) {
var uids, name *http.Cookie
args := arg.(*model.RecommendStateOpReq)
if name, err = c.Request.Cookie("username"); err == nil {
args.UserName = name.Value
}
if uids, err = c.Request.Cookie("uid"); err == nil {
if args.UID, err = strconv.ParseInt(uids.Value, 10, 64); err != nil {
return
}
}
return nil, srv.RecommendOP(cont, arg.(*model.RecommendStateOpReq))
},
"recommendOP")(c)
}
func recommendList(c *blademaster.Context) {
httpGetWriterByExport(
new(model.MCNUPRecommendReq),
func(cont context.Context, arg interface{}) (res interface{}, err error) {
return srv.RecommendList(cont, arg.(*model.MCNUPRecommendReq))
},
"recommendList")(c)
}

View File

@@ -0,0 +1,35 @@
package http
import (
"context"
"go-common/app/admin/main/mcn/model"
"go-common/library/net/http/blademaster"
)
func arcTopDataStatistics(c *blademaster.Context) {
httpGetWriterByExport(
new(model.McnGetRankReq),
func(cont context.Context, arg interface{}) (res interface{}, err error) {
return srv.ArcTopDataStatistics(cont, arg.(*model.McnGetRankReq))
},
"ArcTopDataStatistics")(c)
}
func mcnsTotalDatas(c *blademaster.Context) {
httpGetFunCheckCookie(
new(model.TotalMcnDataReq),
func(cont context.Context, arg interface{}) (res interface{}, err error) {
return srv.McnsTotalDatas(cont, arg.(*model.TotalMcnDataReq))
},
"McnsTotalDatas")(c)
}
func mcnFansAnalyze(c *blademaster.Context) {
httpGetFunCheckCookie(
new(model.McnCommonReq),
func(cont context.Context, arg interface{}) (res interface{}, err error) {
return srv.McnFansAnalyze(cont, arg.(*model.McnCommonReq))
},
"McnFansAnalyze")(c)
}

View File

@@ -0,0 +1,67 @@
package http
import (
"bytes"
"io/ioutil"
"net/http"
"path"
"time"
"go-common/library/ecode"
bm "go-common/library/net/http/blademaster"
)
const (
maxFileSize = 20 << 20
)
func upload(c *bm.Context) {
c.Request.ParseMultipartForm(maxFileSize)
imageFile, header, err := c.Request.FormFile("file")
if err != nil {
c.JSON(nil, err)
return
}
if header.Size > maxFileSize {
c.JSON(nil, ecode.MCNContractFileSize)
return
}
fileExt := path.Ext(header.Filename)
if fileExt == "" {
c.JSON(nil, ecode.MCNUnknownFileTypeErr)
return
}
defer imageFile.Close()
bs, err := ioutil.ReadAll(imageFile)
if err != nil {
c.JSON(nil, err)
return
}
filetype := http.DetectContentType(bs)
switch filetype {
case
"image/jpeg",
"image/jpg",
"image/png",
"application/pdf":
case "application/octet-stream", "application/zip":
switch fileExt[1:] {
case "doc":
filetype = "application/doc"
case "docx":
filetype = "application/docx"
case "docm":
filetype = "application/docm"
}
case "application/msword":
filetype = "application/doc"
case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
filetype = "application/docx"
case "application/vnd.ms-word.document.macroEnabled.12":
filetype = "application/docm"
default:
c.JSON(nil, ecode.MCNUnknownFileTypeErr)
return
}
c.JSON(srv.Upload(c, "", filetype, time.Now().Unix(), bytes.NewReader(bs)))
}