作者 yangfu

库修改

... ... @@ -3,7 +3,7 @@ FROM golang:1.13 as builder
ENV GOPROXY https://goproxy.cn
ENV GO111MODULE on
RUN git clone http://gitlab.fjmaimaimai.com/mmm-go/gocomm.git /app/gocomm
#RUN git clone http://github.com/tiptok/gocomm.git /app/gocomm
WORKDIR /app/ab
... ...
... ... @@ -2,9 +2,9 @@ package controllers
import (
"github.com/astaxie/beego"
"github.com/tiptok/gocomm/pkg/mybeego"
"gitlab.fjmaimaimai.com/mmm-go/ab/protocol"
"gitlab.fjmaimaimai.com/mmm-go/ab/services/ab"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego"
)
type ABController struct {
... ...
... ... @@ -2,9 +2,9 @@ package controllers
import (
"github.com/astaxie/beego/validation"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego"
"github.com/tiptok/gocomm/common"
"github.com/tiptok/gocomm/pkg/log"
"github.com/tiptok/gocomm/pkg/mybeego"
)
type BaseController struct {
... ... @@ -12,16 +12,16 @@ type BaseController struct {
}
//Valid valid struct
func (this *BaseController)Valid(obj interface{})(result bool ,msg *mybeego.Message){
func (this *BaseController) Valid(obj interface{}) (result bool, msg *mybeego.Message) {
/*校验*/
var err error
valid :=validation.Validation{}
result,err= valid.Valid(obj)
if err!=nil{
valid := validation.Validation{}
result, err = valid.Valid(obj)
if err != nil {
msg = mybeego.NewMessage(1)
return
}
if !result{
if !result {
for _, err := range valid.Errors {
log.Error(err.Key, err.Message)
}
... ... @@ -32,14 +32,14 @@ func (this *BaseController)Valid(obj interface{})(result bool ,msg *mybeego.Mess
}
//GenMessage genarate a response message
func (this *BaseController)GenMessage(rsp interface{},err error)*mybeego.Message{
func (this *BaseController) GenMessage(rsp interface{}, err error) *mybeego.Message {
var msg *mybeego.Message
if err==nil{
if err == nil {
msg = mybeego.NewMessage(0)
msg.Data = rsp
return msg
}
if e,ok :=err.(common.Error);ok{
if e, ok := err.(common.Error); ok {
msg = mybeego.NewMessage(e.Code)
msg.Data = rsp
return msg
... ...
package controllers
import (
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego"
"github.com/tiptok/gocomm/pkg/mybeego"
)
type MainController struct {
... ...
... ... @@ -2,10 +2,10 @@ package controllers
import (
"encoding/json"
"github.com/tiptok/gocomm/pkg/log"
"github.com/tiptok/gocomm/pkg/mybeego"
"gitlab.fjmaimaimai.com/mmm-go/ab/protocol"
"gitlab.fjmaimaimai.com/mmm-go/ab/services/history"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
)
type HistoryController struct {
... ... @@ -13,18 +13,18 @@ type HistoryController struct {
}
//SuccessList
func(this *HistoryController)SuccessList(){
func (this *HistoryController) SuccessList() {
var msg *mybeego.Message
defer func(){
defer func() {
this.Resp(msg)
}()
var request *protocol.SuccessListRequest
if err:=json.Unmarshal(this.ByteBody,&request);err!=nil{
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = mybeego.NewMessage(1)
return
}
if b,m :=this.Valid(request);!b{
if b, m := this.Valid(request); !b {
msg = m
return
}
... ... @@ -32,18 +32,18 @@ func(this *HistoryController)SuccessList(){
}
//GetRequest
func(this *HistoryController)GetRequest(){
func (this *HistoryController) GetRequest() {
var msg *mybeego.Message
defer func(){
defer func() {
this.Resp(msg)
}()
var request *protocol.GetRequestRequest
if err:=json.Unmarshal(this.ByteBody,&request);err!=nil{
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = mybeego.NewMessage(1)
return
}
if b,m :=this.Valid(request);!b{
if b, m := this.Valid(request); !b {
msg = m
return
}
... ... @@ -51,18 +51,18 @@ func(this *HistoryController)GetRequest(){
}
//Retry
func(this *HistoryController)Retry(){
func (this *HistoryController) Retry() {
var msg *mybeego.Message
defer func(){
defer func() {
this.Resp(msg)
}()
var request *protocol.RetryRequest
if err:=json.Unmarshal(this.ByteBody,&request);err!=nil{
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = mybeego.NewMessage(1)
return
}
if b,m :=this.Valid(request);!b{
if b, m := this.Valid(request); !b {
msg = m
return
}
... ... @@ -70,18 +70,18 @@ func(this *HistoryController)Retry(){
}
//DeleteHistory
func(this *HistoryController)DeleteHistory(){
func (this *HistoryController) DeleteHistory() {
var msg *mybeego.Message
defer func(){
defer func() {
this.Resp(msg)
}()
var request *protocol.DeleteHistoryRequest
if err:=json.Unmarshal(this.ByteBody,&request);err!=nil{
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = mybeego.NewMessage(1)
return
}
if b,m :=this.Valid(request);!b{
if b, m := this.Valid(request); !b {
msg = m
return
}
... ...
#!/bin/bash
export PATH=/root/local/bin:$PATH
kubectl -n mmm-suplus-dev get pods | grep -q ab
if [ "$?" == "1" ];then
kubectl create -f /tmp/dev/ab/opp.yaml --record
kubectl -n mmm-suplus-dev get svc | grep -q ab
if [ "$?" == "0" ];then
echo "ab service install success!"
else
echo "ab service install fail!"
fi
kubectl -n mmm-suplus-dev get pods | grep -q ab
if [ "$?" == "0" ];then
echo "ab deployment install success!"
else
echo "ab deployment install fail!"
fi
else
kubectl delete -f /tmp/dev/ab/opp.yaml
kubectl -n mmm-suplus-dev get svc | grep -q ab
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-dev get svc | grep -q ab
done
kubectl -n mmm-suplus-dev get pods | grep -q ab
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-dev get pods | grep -q ab
done
kubectl create -f /tmp/dev/ab/opp.yaml --record
kubectl -n mmm-suplus-dev get svc | grep -q ab
if [ "$?" == "0" ];then
echo "ab service update success!"
else
echo "opp service update fail!"
fi
kubectl -n mmm-suplus-dev get pods | grep -q opp
if [ "$?" == "0" ];then
echo "opp deployment update success!"
else
echo "opp deployment update fail!"
fi
fi
\ No newline at end of file
... ...
apiVersion: v1
kind: Service
metadata:
name: ab
namespace: mmm-suplus-dev
labels:
k8s-app: ab
spec:
ports:
- name: "http"
port: 80
targetPort: 8080
selector:
k8s-app: ab
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: ab
namespace: mmm-suplus-dev
labels:
k8s-app: ab
spec:
replicas: 1
template:
metadata:
labels:
k8s-app: ab
spec:
# affinity:
# nodeAffinity:
# preferredDuringSchedulingIgnoredDuringExecution:
# - preference: {}
# weight: 100
# requiredDuringSchedulingIgnoredDuringExecution:
# nodeSelectorTerms:
# - matchExpressions:
# - key: kubernetes.io/hostname
# operator: In
# values:
# - cn-hangzhou.i-bp1djh1xn7taumbue1ze
# - cn-hangzhou.i-bp1djh1xn7taumbue1zd
# - cn-hangzhou.i-bp1euf5u1ph9kbhtndhb
# - cn-hangzhou.i-bp1hyp5oips9cdwxxgxy
containers:
- name: ab
image: hub.docker.com/dk1992/ab:dev
imagePullPolicy: Always
# volumeMounts:
# - mountPath: /opt/logs
# name: accesslogs
# - mountPath: /var/www/opp/file
# name: mmmjihuitest-pvc1
ports:
- containerPort: 8080
env:
- name: MYSQL_HOST
valueFrom:
configMapKeyRef:
name: suplus-config
key: mysql.host
- name: MYSQL_PORT
valueFrom:
configMapKeyRef:
name: suplus-config
key: mysql.port
- name: REDIS_HOST
valueFrom:
configMapKeyRef:
name: suplus-config
key: redis.ip
- name: REDIS_PORT
valueFrom:
configMapKeyRef:
name: suplus-config
key: redis.port
- name: MYSQL_USER
valueFrom:
configMapKeyRef:
name: suplus-config
key: mysql.user
- name: MYSQL_PASSWORD
valueFrom:
configMapKeyRef:
name: suplus-config
key: mysql.password
# - name: MYSQL_DB_NAME
# value: "opportunity_dev"
- name: RUN_MODE
value: "dev-online"
- name: LOG_LEVEL
value: "debug"
- name: aliyun_logs_suplusfile
value: "stdout"
- name: aliyun_logs_access
value: " /opt/logs/app.log"
- name: BUSINESS_ADMIN_SERVICE_HOST
valueFrom:
configMapKeyRef:
name: suplus-config
key: service.businessadmin
# volumes:
# - name: accesslogs
# emptyDir: {}
# - name: mmmjihuitest-pvc1
# persistentVolumeClaim:
# claimName: mmmjihuitest-pvc
\ No newline at end of file
... ...
... ... @@ -4,8 +4,8 @@ go 1.13
require (
github.com/astaxie/beego v1.10.0
github.com/prometheus/common v0.4.0
gitlab.fjmaimaimai.com/mmm-go/gocomm v0.0.1
github.com/prometheus/common v0.9.1
github.com/tiptok/gocomm v1.0.6
)
replace gitlab.fjmaimaimai.com/mmm-go/gocomm => ../gocomm
// replace github.com/tiptok/gocomm => ../gocomm
... ...
... ... @@ -2,20 +2,19 @@ package main
import (
"github.com/astaxie/beego"
"github.com/tiptok/gocomm/config"
"github.com/tiptok/gocomm/pkg/log"
"github.com/tiptok/gocomm/pkg/redis"
_ "gitlab.fjmaimaimai.com/mmm-go/ab/routers"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/config"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/redis"
)
func init(){
func init() {
log.InitLog(config.Logger{
Filename:"app.log",
Level:"7",
Filename: "app.log",
Level: "7",
})
err:= redis.InitWithDb(100,beego.AppConfig.String("redis_add_port"),beego.AppConfig.String("redis_auth"),"0")
if err!=nil{
err := redis.InitWithDb(100, beego.AppConfig.String("redis_add_port"), beego.AppConfig.String("redis_auth"), "0")
if err != nil {
log.Fatal(err)
}
//orm.NewBeeormEngine(config.Mysql{
... ... @@ -26,10 +25,10 @@ func init(){
}
func main() {
defer func(){
defer func() {
log.Info("app on stop!")
}()
log.Info("app on start!")
log.Info("Beego Run Mode:",beego.BConfig.RunMode)
log.Info("Beego Run Mode:", beego.BConfig.RunMode)
beego.Run()
}
... ...
... ... @@ -2,7 +2,7 @@ package protocol
import (
"encoding/json"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"github.com/tiptok/gocomm/pkg/log"
)
/*Compare */
... ...
... ... @@ -5,8 +5,8 @@ import (
"fmt"
"github.com/astaxie/beego"
"github.com/astaxie/beego/httplib"
"github.com/tiptok/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/ab/protocol"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"io/ioutil"
"net/http"
"reflect"
... ...