作者 tangxvhui

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/mmm-go/openapi into dev

... ... @@ -3,6 +3,7 @@ FROM 192.168.0.243:5000/mmm/mmmopp:20200422 as builder
ENV GOPROXY https://goproxy.cn
ENV GO111MODULE on
ENV GOPATH /go
#RUN git clone http://gitlab.fjmaimaimai.com/mmm-go/gocomm.git /go/src/gocomm
RUN cd /go/src/gocomm \
&& git pull
WORKDIR /go/src/openapi
... ... @@ -10,7 +11,7 @@ WORKDIR /go/src/openapi
COPY go.mod .
COPY . .
RUN GOOS=linux CGO_ENABLED=0 go build -ldflags="-s -w" -o opp main.go
RUN GOOS=linux CGO_ENABLED=0 go build -ldflags="-s -w" -o openapi main.go
#FROM alpine:latest
FROM 192.168.0.243:5000/mmm/mmmopp:20200110
... ...
[dev-online]
#Ali could
AccessKeyID ="LTAI4FhiZ3UktC6N1u3H5GFC"
AccessKeySecret ="UyspWwdni55CYQ02hUCint4qY2jNYO"
#日志
log_level = "${LOG_LEVEL||debug}"
aliyun_logs_access ="${aliyun_logs_access||F:/log/app.log}"
#Ali could
AccessKeyID ="LTAI4Fz1LUBW2fXp6QWaJHRS"
AccessKeySecret ="aLZXwK8pgrs10Ws03qcN7NsrSXFVsg"
#阿里云
cname ="https://media.goexample.live/"
#cname ="https://media.goexample.live/"
cname ="https://media.fjmaimaimai.com/"
... ...
[dev]
#Ali could
AccessKeyID ="LTAI4FhiZ3UktC6N1u3H5GFC"
AccessKeySecret ="UyspWwdni55CYQ02hUCint4qY2jNYO"
#AccessKeyID ="LTAI4FhiZ3UktC6N1u3H5GFC"
#AccessKeySecret ="UyspWwdni55CYQ02hUCint4qY2jNYO"
AccessKeyID ="LTAI4Fz1LUBW2fXp6QWaJHRS"
AccessKeySecret ="aLZXwK8pgrs10Ws03qcN7NsrSXFVsg"
#日志
log_level = "${LOG_LEVEL||debug}"
aliyun_logs_access ="${aliyun_logs_access||F:/log/app.log}"
#阿里云
cname ="https://media.goexample.live/"
#阿里云 https://media.goexample.live/
cname ="https://media.fjmaimaimai.com/"
... ...
[prod]
#日志
log_level = "${LOG_LEVEL||debug}"
aliyun_logs_access ="${aliyun_logs_access||F:/log/app.log}"
#Ali could
AccessKeyID ="LTAI4FhiZ3UktC6N1u3H5GFC"
AccessKeySecret ="UyspWwdni55CYQ02hUCint4qY2jNYO"
\ No newline at end of file
AccessKeyID ="LTAI4Fz1LUBW2fXp6QWaJHRS"
AccessKeySecret ="aLZXwK8pgrs10Ws03qcN7NsrSXFVsg"
#阿里云
cname ="https://media.fjmaimaimai.com/"
\ No newline at end of file
... ...
[test]
#日志
log_level = "${LOG_LEVEL||debug}"
aliyun_logs_access ="${aliyun_logs_access||F:/log/app.log}"
#Ali could
AccessKeyID ="LTAI4FhiZ3UktC6N1u3H5GFC"
AccessKeySecret ="UyspWwdni55CYQ02hUCint4qY2jNYO"
\ No newline at end of file
AccessKeyID ="LTAI4Fz1LUBW2fXp6QWaJHRS"
AccessKeySecret ="aLZXwK8pgrs10Ws03qcN7NsrSXFVsg"
#阿里云
cname ="https://media.fjmaimaimai.com/"
\ No newline at end of file
... ...
... ... @@ -118,7 +118,7 @@ var AllowOption = func(ctx *context.Context) {
f := cors.Allow(&cors.Options{
AllowMethods: []string{"POST", "GET", "OPTIONS", "PUT", "DELETE"}, //允许的请求类型
AllowHeaders: []string{"Origin", "Accept", "Content-Type", "Authorization",
"x-mmm-cid", "x-mmm-uid", "x-mmm-accesstoken", "x-mmm-refreshtoken", "x-requested-with"}, //允许的头部信息
"x-mmm-cid", "x-mmm-uid", "x-mmm-accesstoken", "x-mmm-refreshtoken", "x-requested-with", "x-mmm-appproject", "x-mmm-devicetype"}, //允许的头部信息
ExposeHeaders: []string{"Content-Length"}, //允许暴露的头信息
AllowCredentials: false, //不允许共享AuthTuffic证书
AllowAllOrigins: true, //允许的请求来源
... ...
... ... @@ -37,6 +37,43 @@ func (this *VodController) CreateUploadVideo() {
msg = protocol.NewReturnResponse(vod.CreateUploadVideo(header, request))
}
//创建视频上传凭证(多个) CreateUploadVideos
// @router /createUploadVideos [post]
func (this *VodController) CreateUploadVideos() {
var msg *protocol.ResponseMessage
var response *aliyun.CreateUploadVideosResponse = &aliyun.CreateUploadVideosResponse{
List: make([]*aliyun.CreateUploadVideoResponse, 0),
}
defer func() {
this.Resp(msg)
}()
var request *aliyun.CreateUploadVideosRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
var err error
if len(request.Items) == 0 {
msg = protocol.BadRequestParam(2)
}
for i := range request.Items {
r := request.Items[i]
if rsp, e := vod.CreateUploadVideo(header, r); e != nil {
err = e
break
} else {
response.List = append(response.List, rsp)
}
}
msg = protocol.NewReturnResponse(response, err)
}
//刷新视频上传凭证 RefreshUploadVideo
// @router /refreshUploadVideo [post]
func (this *VodController) RefreshUploadVideo() {
... ... @@ -75,6 +112,7 @@ func (this *VodController) CreateUploadImage() {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(vod.CreateUploadImage(header, request))
}
... ... @@ -112,7 +150,6 @@ func (this *VodController) CreateUploadImages() {
err = e
break
} else {
rsp.FileName = r.FileName
response.List = append(response.List, rsp)
}
}
... ...
#!/bin/bash
export PATH=/root/local/bin:$PATH
kubectl -n mmm-suplus-dev get pods | grep -q mmmopenapi
kubectl -n mmm-suplus-dev get pods | grep -q mmm-open-api
if [ "$?" == "1" ];then
kubectl create -f /tmp/dev/mmm-go-opp/opp.yaml --record
kubectl -n mmm-suplus-dev get svc | grep -q mmmopenapi
kubectl create -f /tmp/dev/mmm-open-api/mmm-open-api.yaml --record
kubectl -n mmm-suplus-dev get svc | grep -q mmm-open-api
if [ "$?" == "0" ];then
echo "mmmopenapi service install success!"
echo "mmm-open-api service install success!"
else
echo "mmmopenapi service install fail!"
echo "mmm-open-api service install fail!"
fi
kubectl -n mmm-suplus-dev get pods | grep -q mmmopenapi
kubectl -n mmm-suplus-dev get pods | grep -q mmm-open-api
if [ "$?" == "0" ];then
echo "mmmopenapi deployment install success!"
echo "mmm-open-api deployment install success!"
else
echo "mmmopenapi deployment install fail!"
echo "mmm-open-api deployment install fail!"
fi
else
kubectl delete -f /tmp/dev/mmm-go-opp/opp.yaml
kubectl -n mmm-suplus-dev get svc | grep -q mmmopenapi
kubectl delete -f /tmp/dev/mmm-open-api/mmm-open-api.yaml
kubectl -n mmm-suplus-dev get svc | grep -q mmm-open-api
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-dev get svc | grep -q mmmopenapi
kubectl -n mmm-suplus-dev get svc | grep -q mmm-open-api
done
kubectl -n mmm-suplus-dev get pods | grep -q mmmopenapi
kubectl -n mmm-suplus-dev get pods | grep -q mmm-open-api
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-dev get pods | grep -q mmmopenapi
kubectl -n mmm-suplus-dev get pods | grep -q mmm-open-api
done
kubectl create -f /tmp/dev/mmm-go-opp/opp.yaml --record
kubectl -n mmm-suplus-dev get svc | grep -q mmmopenapi
kubectl create -f /tmp/dev/mmm-open-api/mmm-open-api.yaml --record
kubectl -n mmm-suplus-dev get svc | grep -q mmm-open-api
if [ "$?" == "0" ];then
echo "mmmopenapi service update success!"
echo "mmm-open-api service update success!"
else
echo "opp service update fail!"
fi
... ...
apiVersion: v1
kind: Service
metadata:
name: mmmopenapi
name: mmm-open-api
namespace: mmm-suplus-dev
labels:
k8s-app: mmmopenapi
k8s-app: mmm-open-api
spec:
ports:
- name: "http"
port: 80
targetPort: 8080
selector:
k8s-app: mmmopenapi
k8s-app: mmm-open-api
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: mmmopenapi
name: mmm-open-api
namespace: mmm-suplus-dev
labels:
k8s-app: mmmopenapi
k8s-app: mmm-open-api
spec:
replicas: 1
template:
metadata:
labels:
k8s-app: mmmopenapi
k8s-app: mmm-open-api
spec:
affinity:
nodeAffinity:
... ... @@ -43,8 +43,8 @@ spec:
- cn-hangzhou.i-bp1euf5u1ph9kbhtndhb
- cn-hangzhou.i-bp1hyp5oips9cdwxxgxy
containers:
- name: mmmopenapi
image: 192.168.0.243:5000/mmm/mmmopenapi:dev
- name: mmm-open-api
image: 192.168.0.243:5000/mmm/mmm-open-api:dev
imagePullPolicy: Always
volumeMounts:
- mountPath: /opt/logs
... ... @@ -84,8 +84,6 @@ spec:
configMapKeyRef:
name: suplus-config
key: mysql.password
- name: MYSQL_DB_NAME
value: "opportunity_dev"
- name: RUN_MODE
value: "dev-online"
- name: LOG_LEVEL
... ...
#!/bin/bash
export PATH=/root/local/bin:$PATH
kubectl -n mmm-suplus-prd get pods | grep -q mmmopp
kubectl -n mmm-suplus-prd get pods | grep -q mmm-open-api
if [ "$?" == "1" ];then
kubectl create -f /tmp/prd/mmm-go-opp/opp.yaml --record
kubectl -n mmm-suplus-prd get svc | grep -q mmmopp
kubectl create -f /tmp/prd/mmm-open-api/mmm-open-api.yaml --record
kubectl -n mmm-suplus-prd get svc | grep -q mmm-open-api
if [ "$?" == "0" ];then
echo "mmmopp service install success!"
echo "mmm-open-api service install success!"
else
echo "mmmopp service install fail!"
echo "mmm-open-api service install fail!"
fi
kubectl -n mmm-suplus-prd get pods | grep -q mmmopp
kubectl -n mmm-suplus-prd get pods | grep -q mmm-open-api
if [ "$?" == "0" ];then
echo "mmmopp deployment install success!"
echo "mmm-open-api deployment install success!"
else
echo "mmmopp deployment install fail!"
echo "mmm-open-api deployment install fail!"
fi
else
kubectl delete -f /tmp/prd/mmm-go-opp/opp.yaml
kubectl -n mmm-suplus-prd get svc | grep -q mmmopp
kubectl delete -f /tmp/prd/mmm-open-api/mmm-open-api.yaml
kubectl -n mmm-suplus-prd get svc | grep -q mmm-open-api
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-prd get svc | grep -q mmmopp
kubectl -n mmm-suplus-prd get svc | grep -q mmm-open-api
done
kubectl -n mmm-suplus-prd get pods | grep -q mmmopp
kubectl -n mmm-suplus-prd get pods | grep -q mmm-open-api
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-prd get pods | grep -q mmmopp
kubectl -n mmm-suplus-prd get pods | grep -q mmm-open-api
done
kubectl create -f /tmp/prd/mmm-go-opp/opp.yaml --record
kubectl -n mmm-suplus-prd get svc | grep -q mmmopp
kubectl create -f /tmp/prd/mmm-open-api/mmm-open-api.yaml --record
kubectl -n mmm-suplus-prd get svc | grep -q mmm-open-api
if [ "$?" == "0" ];then
echo "mmmopp service update success!"
echo "mmm-open-api service update success!"
else
echo "opp service update fail!"
echo "mmm-open-api service update fail!"
fi
kubectl -n mmm-suplus-prd get pods | grep -q opp
kubectl -n mmm-suplus-prd get pods | grep -q mmm-open-api
if [ "$?" == "0" ];then
echo "opp deployment update success!"
echo "mmm-open-api deployment update success!"
else
echo "opp deployment update fail!"
echo "mmm-open-api deployment update fail!"
fi
fi
\ No newline at end of file
... ...
apiVersion: v1
kind: Service
metadata:
name: mmmopp
name: mmm-open-api
namespace: mmm-suplus-prd
labels:
k8s-app: mmmopp
k8s-app: mmm-open-api
spec:
ports:
- name: "http"
port: 80
targetPort: 8080
- name: "https"
port: 443
targetPort: 443
selector:
k8s-app: mmmopp
k8s-app: mmm-open-api
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: mmmopp
name: mmm-open-api
namespace: mmm-suplus-prd
labels:
k8s-app: mmmopp
k8s-app: mmm-open-api
spec:
replicas: 1
template:
metadata:
labels:
k8s-app: mmmopp
k8s-app: mmm-open-api
spec:
affinity:
nodeAffinity:
... ... @@ -46,17 +43,16 @@ spec:
- cn-hangzhou.i-bp1euf5u1ph9kbhtndhb
- cn-hangzhou.i-bp1hyp5oips9cdwxxgxy
containers:
- name: mmmopp
image: 192.168.0.243:5000/mmm/mmmopp:master
- name: mmm-open-api
image: 192.168.0.243:5000/mmm/mmm-open-api:dev
imagePullPolicy: Always
volumeMounts:
- mountPath: /opt/logs
name: accesslogs
- mountPath: /var/www/opp/file
name: opportunity-pvc1
name: mmmjihuitest-pvc1
ports:
- containerPort: 8080
- containerPort: 443
env:
- name: MYSQL_HOST
valueFrom:
... ... @@ -88,8 +84,6 @@ spec:
configMapKeyRef:
name: suplus-config
key: mysql.password
- name: MYSQL_DB_NAME
value: "opportunity"
- name: RUN_MODE
value: "prod"
- name: LOG_LEVEL
... ... @@ -101,6 +95,6 @@ spec:
volumes:
- name: accesslogs
emptyDir: {}
- name: opportunity-pvc1
- name: mmmjihuitest-pvc1
persistentVolumeClaim:
claimName: opportunity-pvc5
\ No newline at end of file
claimName: mmmjihuitest-pvc
\ No newline at end of file
... ...
#!/bin/bash
export PATH=/root/local/bin:$PATH
kubectl -n mmm-suplus-test get pods | grep -q mmmopp
kubectl -n mmm-suplus-test get pods | grep -q mmm-open-api
if [ "$?" == "1" ];then
kubectl create -f /tmp/test/mmm-go-opp/opp.yaml --record
kubectl -n mmm-suplus-test get svc | grep -q mmmopp
kubectl create -f /tmp/test/mmm-open-api/mmm-open-api.yaml --record
kubectl -n mmm-suplus-test get svc | grep -q mmm-open-api
if [ "$?" == "0" ];then
echo "mmmopp service install success!"
echo "mmm-open-api service install success!"
else
echo "mmmopp service install fail!"
echo "mmm-open-api service install fail!"
fi
kubectl -n mmm-suplus-test get pods | grep -q mmmopp
kubectl -n mmm-suplus-test get pods | grep -q mmm-open-api
if [ "$?" == "0" ];then
echo "mmmopp deployment install success!"
echo "mmm-open-api deployment install success!"
else
echo "mmmopp deployment install fail!"
echo "mmm-open-api deployment install fail!"
fi
else
kubectl delete -f /tmp/test/mmm-go-opp/opp.yaml
kubectl -n mmm-suplus-test get svc | grep -q mmmopp
kubectl delete -f /tmp/test/mmm-open-api/mmm-open-api.yaml
kubectl -n mmm-suplus-test get svc | grep -q mmm-open-api
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-test get svc | grep -q mmmopp
kubectl -n mmm-suplus-test get svc | grep -q mmm-open-api
done
kubectl -n mmm-suplus-test get pods | grep -q mmmopp
kubectl -n mmm-suplus-test get pods | grep -q mmm-open-api
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-test get pods | grep -q mmmopp
kubectl -n mmm-suplus-test get pods | grep -q mmm-open-api
done
kubectl create -f /tmp/test/mmm-go-opp/opp.yaml --record
kubectl -n mmm-suplus-test get svc | grep -q mmmopp
kubectl create -f /tmp/test/mmm-open-api/mmm-open-api.yaml --record
kubectl -n mmm-suplus-test get svc | grep -q mmm-open-api
if [ "$?" == "0" ];then
echo "mmmopp service update success!"
echo "mmm-open-api service update success!"
else
echo "opp service update fail!"
fi
... ...
apiVersion: v1
kind: Service
metadata:
name: mmmopp
name: mmm-open-api
namespace: mmm-suplus-test
labels:
k8s-app: mmmopp
k8s-app: mmm-open-api
spec:
ports:
- name: "http"
port: 80
targetPort: 8080
- name: "https"
port: 443
targetPort: 443
selector:
k8s-app: mmmopp
k8s-app: mmm-open-api
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: mmmopp
name: mmm-open-api
namespace: mmm-suplus-test
labels:
k8s-app: mmmopp
k8s-app: mmm-open-api
spec:
replicas: 1
template:
metadata:
labels:
k8s-app: mmmopp
k8s-app: mmm-open-api
spec:
affinity:
nodeAffinity:
... ... @@ -46,17 +43,16 @@ spec:
- cn-hangzhou.i-bp1euf5u1ph9kbhtndhb
- cn-hangzhou.i-bp1hyp5oips9cdwxxgxy
containers:
- name: mmmopp
image: 192.168.0.243:5000/mmm/mmmopp:dev
- name: mmm-open-api
image: 192.168.0.243:5000/mmm/mmm-open-api:dev
imagePullPolicy: Always
volumeMounts:
- mountPath: /opt/logs
name: accesslogs
- mountPath: /var/www/opp/file
name: mmmjihuitest2-pvc1
name: mmmjihuitest-pvc1
ports:
- containerPort: 8080
- containerPort: 443
env:
- name: MYSQL_HOST
valueFrom:
... ... @@ -88,8 +84,6 @@ spec:
configMapKeyRef:
name: suplus-config
key: mysql.password
- name: MYSQL_DB_NAME
value: "opportunity_test"
- name: RUN_MODE
value: "test"
- name: LOG_LEVEL
... ... @@ -101,6 +95,6 @@ spec:
volumes:
- name: accesslogs
emptyDir: {}
- name: mmmjihuitest2-pvc1
- name: mmmjihuitest-pvc1
persistentVolumeClaim:
claimName: mmmjihuitest2-pvc
\ No newline at end of file
claimName: mmmjihuitest-pvc
\ No newline at end of file
... ...
... ... @@ -5,6 +5,7 @@ go 1.12
require (
github.com/aliyun/alibaba-cloud-sdk-go v1.60.348
github.com/astaxie/beego v1.10.0
github.com/klauspost/cpuid v1.2.3 // indirect
gitlab.fjmaimaimai.com/mmm-go/gocomm v0.0.1
)
... ...
package aliyun
import "fmt"
var (
OssErrFileFormat = fmt.Errorf("文件名格式有错")
)
//创建视频上传凭证
/*CreateUploadVideo */
type CreateUploadVideoRequest struct {
FileName string `json:"fileName"`
Title string `json:"title"`
}
type CreateUploadVideoResponse struct {
FileName string `json:"fileName"`
RequestId string `json:"requestId"`
VideoId string `json:"videoId"`
UploadAddress string `json:"uploadAddress"`
... ... @@ -14,6 +22,14 @@ type CreateUploadVideoResponse struct {
FileURL string `json:"fileURL"`
}
/*CreateUploadVideos */
type CreateUploadVideosRequest struct {
Items []*CreateUploadVideoRequest `json:"items"`
}
type CreateUploadVideosResponse struct {
List []*CreateUploadVideoResponse `json:"list"`
}
//刷新视频上传凭证 RefreshUploadVideo
type RefreshUploadVideoRequest struct {
VideoId string `json:"videoId" valid:"Required;"`
... ...
... ... @@ -2,6 +2,7 @@ package aliyun
type CreateUploadImageRequest struct {
FileName string `json:"fileName"`
Title string `json:"title"`
}
type CreateUploadImageResponse struct {
... ...
... ... @@ -4,9 +4,16 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"path/filepath"
"strings"
)
var (
VoiceFileExt = ".mp3.wma.wav.aac.ra.m4a.flac.ape.ac3.amr"
ImageFileExt = ".png.jpg.jpeg.gif"
VideoFileExt = ".mp4.ts.3gp.mpg.mpeg.mpe.dat.vob.asf"
)
type UploadAddress struct {
Endpoint string
Bucket string
... ... @@ -38,3 +45,19 @@ func ParseUploadAddress(uploadAddress string) (up UploadAddress, err error) {
}
return
}
func validFileExt(rule string, ext string) bool {
if strings.ContainsAny(rule, strings.ToLower(ext)) {
return true
}
return false
}
//@rule 规则
func ValidFileExt(rule, filename string) bool {
if len(filename) == 0 {
return false
}
ext := filepath.Ext(filename)
return validFileExt(rule, ext)
}
... ...
... ... @@ -41,12 +41,8 @@ func InitVodClient(accessKeyId string, accessKeySecret string) (client *vod.Clie
//获取视频上传地址和凭证,并创建视频信息
func CreateUploadVideo(client *vod.Client, r *CreateUploadVideoRequest) (response *CreateUploadVideoResponse, err error) {
request := vod.CreateCreateUploadVideoRequest()
filePath := getFileName(FileVideo, r.FileName)
if filepath.Ext(r.FileName) == "mp3" {
filePath = getFileName(FileVoice, r.FileName)
}
request.Title = filePath
request.FileName = filePath
request.Title = r.Title
request.FileName = r.FileName
request.AcceptFormat = "JSON"
rsp, err := client.CreateUploadVideo(request)
if err != nil {
... ... @@ -58,11 +54,6 @@ func CreateUploadVideo(client *vod.Client, r *CreateUploadVideoRequest) (respons
UploadAddress: rsp.UploadAddress,
UploadAuth: rsp.UploadAuth,
}
if up, e := ParseUploadAddress(rsp.UploadAddress); e != nil {
log.Error(e)
} else {
response.FileURL = up.GetFileUrl(beego.AppConfig.String("cname"))
}
return
}
... ... @@ -90,9 +81,12 @@ func RefreshUploadVideo(client *vod.Client, r *RefreshUploadVideoRequest) (respo
//获取图片上传地址和凭证,并创建视频信息
func CreateUploadImage(client *vod.Client, r *CreateUploadImageRequest) (response *CreateUploadImageResponse, err error) {
request := vod.CreateCreateUploadImageRequest()
filePath := getFileName(FileImage, r.FileName)
request.ImageType = "default"
request.Title = filePath
request.Title = r.Title
if filepath.Ext(r.FileName) == "" {
err = fmt.Errorf("filename:%v invalid", r.FileName)
return
}
request.ImageExt = filepath.Ext(r.FileName)[1:]
request.AcceptFormat = "JSON"
//request.StorageLocation = filepath.Base(request.Title)
... ... @@ -127,7 +121,7 @@ func GetGetVideoPlayAuth(client *vod.Client, r *GetVideoPlayAuthRequest) (respon
}
//fileType: video voice image
func getFileName(fileType string, filename string) string {
func GetFileName(fileType string, filename string) string {
date := comm_time.GetTimeByYyyymmdd()
subfix := path.Ext(filename)
prefix := fmt.Sprintf("%v_%v", time.Now().Unix(), common.RandomString(32))
... ...
package utils
import "os"
import (
"fmt"
"github.com/astaxie/beego"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
comm_time "gitlab.fjmaimaimai.com/mmm-go/gocomm/time"
"os"
"path"
"time"
)
// 判断所给路径文件/文件夹是否存在
func Exists(path string) bool {
... ... @@ -27,3 +35,16 @@ func IsDir(path string) bool {
func IsFile(path string) bool {
return !IsDir(path)
}
//fileType: video voice image
func GetFileName(projectName, fileType string, filename string) string {
date := comm_time.GetTimeByYyyymmdd()
subfix := path.Ext(filename)
if len(projectName) == 0 {
projectName = beego.BConfig.AppName
}
prefix := fmt.Sprintf("%v_%v", time.Now().Unix(), common.RandomString(32))
filename = fmt.Sprintf("%v%v", prefix, subfix)
sourcePath := fmt.Sprintf("%v/%v/%v/%v/%v", projectName, beego.BConfig.RunMode, date, fileType, filename)
return sourcePath
}
... ...
package main
import (
"fmt"
"github.com/astaxie/beego"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/config"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"openapi/internal/utils"
_ "openapi/routers"
"time"
)
func init() {
time.Local = time.FixedZone("CST", 3600*8)
log.InitLog(config.Logger{
Filename: beego.AppConfig.String("aliyun_logs_access"),
Level: fmt.Sprintf("%v", utils.ResolveLogLevel(beego.AppConfig.String("log_level"))),
})
}
func main() {
defer func() {
log.Info("app on stop!")
log.Info("open-api on stop!")
}()
log.Info("app on start!")
log.Info("open-api on start!")
log.Info("Beego Run Mode:", beego.BConfig.RunMode)
beego.Run()
... ...
package protocol
var errmessge ErrorMap = map[int]string{
0: "成功",
1: "系统异常",
2: "参数错误",
0: "成功",
1: "系统异常",
2: "参数错误",
113: "签名验证失败",
}
... ...
package routers
import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/context/param"
)
func init() {
beego.GlobalControllerRouter["openapi/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["openapi/controllers/v1:VodController"],
beego.ControllerComments{
Method: "CreateUploadImage",
Router: `/createUploadImage`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["openapi/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["openapi/controllers/v1:VodController"],
beego.ControllerComments{
Method: "CreateUploadImages",
Router: `/createUploadImages`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["openapi/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["openapi/controllers/v1:VodController"],
beego.ControllerComments{
Method: "CreateUploadVideo",
Router: `/createUploadVideo`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["openapi/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["openapi/controllers/v1:VodController"],
beego.ControllerComments{
Method: "CreateUploadVideos",
Router: `/createUploadVideos`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["openapi/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["openapi/controllers/v1:VodController"],
beego.ControllerComments{
Method: "GetPlayInfo",
Router: `/getPlayInfo`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["openapi/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["openapi/controllers/v1:VodController"],
beego.ControllerComments{
Method: "GetVideoPlayAuth",
Router: `/getVideoPlayAuth`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["openapi/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["openapi/controllers/v1:VodController"],
beego.ControllerComments{
Method: "RefreshUploadVideo",
Router: `/refreshUploadVideo`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
}
... ...
... ... @@ -9,8 +9,10 @@ import (
var nsV1 *beego.Namespace
func init() {
nsVod := beego.NewNamespace("vod", beego.NSBefore(controllers.LogRequestData), beego.NSBefore(controllers.AllowOption), beego.NSInclude(&v1.VodController{}))
nsV1 := beego.NewNamespace("v1",
beego.NSNamespace("vod", beego.NSBefore(controllers.AllowOption), beego.NSInclude(&v1.VodController{})),
//beego.NSNamespace("vod", beego.NSBefore(controllers.FilterComm), beego.NSBefore(controllers.AllowOption), beego.NSInclude(&v1.VodController{})),
)
beego.SetStaticPath("/log", beego.AppConfig.String("aliyun_logs_access"))
beego.AddNamespace(nsVod)
beego.AddNamespace(nsV1)
}
... ...
package vod
import (
"openapi/internal/aliyun"
"openapi/protocol"
)
//错误处理
func ErrorHandler(in error) (err error) {
switch in {
case aliyun.OssErrFileFormat:
err = protocol.NewCustomMessage(2, in.Error())
break
default:
err = in
return
}
return
}
... ...
package vod
import (
"github.com/astaxie/beego"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"openapi/internal/aliyun"
"openapi/internal/utils"
"openapi/protocol"
)
//创建视频上传凭证
func CreateUploadVideo(header *protocol.RequestHeader, request *aliyun.CreateUploadVideoRequest) (rsp *aliyun.CreateUploadVideoResponse, err error) {
var ()
var (
up aliyun.UploadAddress
filePath string
fileName = request.FileName
)
defer func() {
err = ErrorHandler(err)
}()
client, e := aliyun.DefaultVodClient()
if e != nil {
log.Error(e)
err = e
return
}
if aliyun.ValidFileExt(aliyun.VideoFileExt, request.FileName) {
filePath = utils.GetFileName(header.AppProject, aliyun.FileVideo, request.FileName)
} else if aliyun.ValidFileExt(aliyun.VoiceFileExt, request.FileName) {
filePath = utils.GetFileName(header.AppProject, aliyun.FileVoice, request.FileName)
} else {
err = aliyun.OssErrFileFormat
return
}
request.FileName = filePath
request.Title = filePath
rsp, err = aliyun.CreateUploadVideo(client, request)
if err != nil {
log.Error(err)
return
}
if up, err = aliyun.ParseUploadAddress(rsp.UploadAddress); err != nil {
log.Error(err)
return
}
rsp.FileName = fileName
rsp.FileURL = up.GetFileUrl(beego.AppConfig.String("cname"))
return
}
... ... @@ -50,8 +76,13 @@ func CreateUploadImage(header *protocol.RequestHeader, request *aliyun.CreateUpl
if len(request.FileName) == 0 {
request.FileName = aliyun.DefaultImageFileName
}
if !aliyun.ValidFileExt(aliyun.ImageFileExt, request.FileName) {
return nil, aliyun.OssErrFileFormat
}
request.Title = utils.GetFileName(header.AppProject, aliyun.FileImage, request.FileName)
rsp, err = aliyun.CreateUploadImage(client, request)
rsp.FileURL = rsp.ImageURL
rsp.FileName = request.FileName
if err != nil {
log.Error(err)
}
... ...