作者 yangfu

edit config

... ... @@ -19,7 +19,7 @@ FROM alpine:latest
# Define the project name | 定义项目名称
ARG PROJECT=core
# Define the config file name | 定义配置文件名
ARG CONFIG_FILE=core.yaml
ARG CONFIG_FILE=core-dev.yaml
# Define the author | 定义作者
ARG AUTHOR=785409885@qq.com
... ...
... ... @@ -2,7 +2,7 @@ package main
import (
"flag"
"fmt"
"github.com/zeromicro/go-zero/core/logx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
"net/http"
... ... @@ -57,6 +57,6 @@ func main() {
db.Migrate(ctx.DB)
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
logx.Infof("Starting server at %s:%d...\n", c.Host, c.Port)
server.Start()
}
... ...
Name: chart
Host: 0.0.0.0
Port: 8080
Verbose: true
Log:
Mode: file
Encoding: plain
Level: debug # info
JwtAuth:
AccessSecret: digital-platform
Expire: 360000
Redis:
Host: 192.168.0.243:6379
Type: node
Pass:
DB:
DataSource: host=114.55.200.59 user=postgres password=eagle1010 dbname=sumifcc-bchart-dev port=31543 sslmode=disable TimeZone=Asia/Shanghai
ByteMetadata:
Name: ApiByteMetadata
Host: http://character-library-metadata-bastion-test.fjmaimaimai.com
Timeout: 0s
\ No newline at end of file
... ...
Name: chart
Host: 0.0.0.0
Port: 8080
Port: 8081
Verbose: true
Log:
Mode: file
Encoding: plain
Level: debug # info
MaxSize: 1 # 2MB
TimeFormat: 2006-01-02 15:04:05.000
JwtAuth:
AccessSecret: digital-platform
Expire: 360000
... ...
package log
import (
"net/http"
"path/filepath"
"strings"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
)
func GetLogHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.LogGetRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
path := svcCtx.Config.Log.Path
if svcCtx.Config.Log.Mode != "file" {
return
}
if path == "" {
path = "logs"
}
if !strings.HasSuffix(req.Module, ".log") {
req.Module += ".log"
}
handler := http.FileServer(http.Dir(path))
r.URL.Path = filepath.Join(req.Module)
handler.ServeHTTP(w, r)
}
}
... ...
... ... @@ -5,6 +5,7 @@ import (
"net/http"
chart "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/handler/chart"
log "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/handler/log"
page "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/handler/page"
table "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/handler/table"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
... ... @@ -161,4 +162,15 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
rest.WithPrefix("/v1"),
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodGet,
Path: "/log/:module",
Handler: log.GetLogHandler(serverCtx),
},
},
rest.WithPrefix("/v1"),
)
}
... ...
... ... @@ -76,6 +76,7 @@ func (l *SaveChartLogic) SaveChart(req *types.ChartSaveRequest) (resp *types.Cha
Title: chartProperty.Title,
TableAbility: chartProperty.TableAbility,
Series: chartProperty.Series,
Other: chartProperty.Other,
TenantId: chart.TenantId,
}
if chartSetting, err = l.svcCtx.ChartSettingRepository.Insert(l.ctx, conn, chartSetting); err != nil {
... ...
package log
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetLogLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetLogLogic {
return &GetLogLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetLogLogic) GetLog(req *types.LogGetRequest) (resp *types.LogGetResponse, err error) {
// todo: add your logic here and delete this line
return
}
... ...
... ... @@ -27,7 +27,7 @@ type ServiceContext struct {
}
func NewServiceContext(c config.Config) *ServiceContext {
db := database.OpenGormPGDB(c.DB.DataSource)
db := database.OpenGormPGDB(c.DB.DataSource, c.Log.Mode)
mlCache := cache.NewMultiLevelCache([]string{c.Redis.Host}, c.Redis.Pass)
redisCache := gzcache.NewClusterCache([]string{c.Redis.Host}, c.Redis.Pass)
redis, _ := redis.NewRedis(redis.RedisConf{Host: c.Redis.Host, Pass: c.Redis.Pass, Type: "node"})
... ...
... ... @@ -298,3 +298,10 @@ type GetAppPageShareDetailRequest struct {
type GetAppPageShareDetailResponse struct {
AppPage AppPageItem `json:"page"`
}
type LogGetRequest struct {
Module string `path:"module"`
}
type LogGetResponse struct {
}
... ...
#!/bin/bash
export PATH=/root/local/bin:$PATH
kubectl -n mmm-suplus-dev get pods | grep -q sumifcc-bchart
if [ "$?" == "1" ];then
kubectl create -f /tmp/dev/sumifcc-bchart/sumifcc-bchart.yaml --record
kubectl -n mmm-suplus-dev get svc | grep -q sumifcc-bchart
if [ "$?" == "0" ];then
echo "sumifcc-bchart service install success!"
else
echo "sumifcc-bchart service install fail!"
fi
kubectl -n mmm-suplus-dev get pods | grep -q sumifcc-bchart
if [ "$?" == "0" ];then
echo "sumifcc-bchart deployment install success!"
else
echo "sumifcc-bchart deployment install fail!"
fi
else
kubectl delete -f /tmp/dev/sumifcc-bchart/sumifcc-bchart.yaml
kubectl -n mmm-suplus-dev get svc | grep -q sumifcc-bchart
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-dev get svc | grep -q sumifcc-bchart
done
kubectl -n mmm-suplus-dev get pods | grep -q sumifcc-bchart
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-dev get pods | grep -q sumifcc-bchart
done
kubectl create -f /tmp/dev/sumifcc-bchart/sumifcc-bchart.yaml --record
kubectl -n mmm-suplus-dev get svc | grep -q sumifcc-bchart
if [ "$?" == "0" ];then
echo "sumifcc-bchart service update success!"
else
echo "sumifcc-bchart service update fail!"
fi
kubectl -n mmm-suplus-dev get pods | grep -q sumifcc-bchart
if [ "$?" == "0" ];then
echo "sumifcc-bchart deployment update success!"
else
echo "sumifcc-bchart deployment update fail!"
fi
fi
\ No newline at end of file
... ...
apiVersion: v1
kind: Service
metadata:
name: sumifcc-bchart
namespace: mmm-suplus-dev
labels:
k8s-app: sumifcc-bchart
spec:
ports:
- name: "http"
port: 80
targetPort: 8080
selector:
k8s-app: sumifcc-bchart
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: sumifcc-bchart
namespace: mmm-suplus-dev
labels:
k8s-app: sumifcc-bchart
spec:
replicas: 1
template:
metadata:
labels:
k8s-app: sumifcc-bchart
spec:
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- preference: {}
weight: 100
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- cn-hangzhou.i-bp1djh1xn7taumbue1zd
containers:
- name: sumifcc-bchart
image: 192.168.0.243:5000/mmm/sumifcc-bchart:dev
imagePullPolicy: Always
ports:
- containerPort: 8080
volumeMounts:
- mountPath: /opt/logs
name: accesslogs
env:
- name: LOG_LEVEL
value: "debug"
- name: ERROR_BASE_CODE
value: "1"
- name: ERROR_BASE_CODE_MULTIPLE
value: "1000"
volumes:
- name: accesslogs
emptyDir: {}
\ No newline at end of file
... ...
#!/bin/bash
export PATH=/root/local/bin:$PATH
kubectl -n <replace-your-k8s-namespace> get pods | grep -q sumifcc-survey-server
if [ "$?" == "1" ];then
kubectl create -f /tmp/dev/sumifcc-survey-server/sumifcc-survey-server.yaml --record
kubectl -n <replace-your-k8s-namespace> get svc | grep -q sumifcc-survey-server
if [ "$?" == "0" ];then
echo "sumifcc-survey-server service install success!"
else
echo "sumifcc-survey-server service install fail!"
fi
kubectl -n <replace-your-k8s-namespace> get pods | grep -q sumifcc-survey-server
if [ "$?" == "0" ];then
echo "sumifcc-survey-server deployment install success!"
else
echo "sumifcc-survey-server deployment install fail!"
fi
else
kubectl delete -f /tmp/dev/sumifcc-survey-server/sumifcc-survey-server.yaml
kubectl -n <replace-your-k8s-namespace> get svc | grep -q sumifcc-survey-server
while [ "$?" == "0" ]
do
kubectl -n <replace-your-k8s-namespace> get svc | grep -q sumifcc-survey-server
done
kubectl -n <replace-your-k8s-namespace> get pods | grep -q sumifcc-survey-server
while [ "$?" == "0" ]
do
kubectl -n <replace-your-k8s-namespace> get pods | grep -q sumifcc-survey-server
done
kubectl create -f /tmp/dev/sumifcc-survey-server/sumifcc-survey-server.yaml --record
kubectl -n <replace-your-k8s-namespace> get svc | grep -q sumifcc-survey-server
if [ "$?" == "0" ];then
echo "sumifcc-survey-server service update success!"
else
echo "sumifcc-survey-server service update fail!"
fi
kubectl -n <replace-your-k8s-namespace> get pods | grep -q sumifcc-survey-server
if [ "$?" == "0" ];then
echo "sumifcc-survey-server deployment update success!"
else
echo "sumifcc-survey-server deployment update fail!"
fi
fi
\ No newline at end of file
... ...
apiVersion: v1
kind: Service
metadata:
name: sumifcc-survey-server
namespace: <replace-your-k8s-namespace>
labels:
k8s-app: sumifcc-survey-server
spec:
ports:
- name: "http"
port: 80
targetPort: 8082
selector:
k8s-app: sumifcc-survey-server
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: sumifcc-survey-server
namespace: <replace-your-k8s-namespace>
labels:
k8s-app: sumifcc-survey-server
spec:
replicas: 1
template:
metadata:
labels:
k8s-app: sumifcc-survey-server
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: sumifcc-survey-server
image: 192.168.0.243:5000/mmm/sumifcc-survey-server:dev
imagePullPolicy: Always
ports:
- containerPort: 8082
volumeMounts:
- mountPath: /opt/logs
name: accesslogs
env:
- name: LOG_LEVEL
value: "debug"
- name: ERROR_BASE_CODE
value: "1"
- name: ERROR_BASE_CODE_MULTIPLE
value: "1000"
volumes:
- name: accesslogs
emptyDir: {}
\ No newline at end of file
... ...
import "core/chart.api"
import "core/table.api"
import "core/app_page.api"
import "core/log.api"
// import "./core/chart_stting.api"
\ No newline at end of file
... ...
syntax = "v1"
info(
title: "天联字库图表模板"
desc: "图表模板"
author: "小火箭"
email: "email"
version: "v1"
)
@server(
prefix: v1
group: log
)
service Core {
@doc "获取图表详情"
@handler getLog
get /log/:module (LogGetRequest) returns (LogGetResponse)
}
type(
LogGetRequest struct{
Module string `path:"module"`
}
LogGetResponse struct{
}
)
\ No newline at end of file
... ...
package cache
import (
"fmt"
"github.com/tiptok/gocomm/pkg/cache"
"github.com/tiptok/gocomm/pkg/cache/gzcache"
"github.com/tiptok/gocomm/pkg/log"
"github.com/zeromicro/go-zero/core/logx"
)
func NewMultiLevelCache(hosts []string, password string) *cache.MultiLevelCache {
fmt.Println("starting multi level cache...")
logx.Infof("starting multi level cache...")
mlCache := cache.NewMultiLevelCacheNew(cache.WithDebugLog(true, func() log.Log {
return log.DefaultLog
}))
... ...
package database
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/logx"
"gorm.io/driver/mysql"
"gorm.io/driver/postgres"
"gorm.io/gorm"
... ... @@ -31,28 +33,52 @@ func OpenGormDB(source string) *gorm.DB {
return db
}
func OpenGormPGDB(source string) *gorm.DB {
newLogger := logger.New(
log.New(os.Stdout, "\r\n", log.LstdFlags), // io writer
logger.Config{
SlowThreshold: time.Second, // Slow SQL threshold
LogLevel: logger.Info, // Log level
IgnoreRecordNotFoundError: true, // Ignore ErrRecordNotFound error for logger
Colorful: false, // Disable color
},
)
fmt.Println("starting db...")
//db, err := gorm.Open(postgres.Open(source), &gorm.Config{
// Logger: newLogger,
//})
func OpenGormPGDB(source string, logMode string) *gorm.DB {
logx.Infof("starting db...")
db, err := gorm.Open(postgres.New(postgres.Config{
DSN: source,
PreferSimpleProtocol: true, // disables implicit prepared statement usage
}), &gorm.Config{
Logger: newLogger,
Logger: NewLogger(logMode), //newLogger,
})
if err != nil {
panic(err)
}
return db
}
func NewLogger(logType string) logger.Interface {
if logType == "console" {
return logger.New(
log.New(os.Stdout, "\r\n", log.LstdFlags), // io writer
logger.Config{
SlowThreshold: time.Second, // Slow SQL threshold
LogLevel: logger.Info, // Log level
IgnoreRecordNotFoundError: true, // Ignore ErrRecordNotFound error for logger
Colorful: false, // Disable color
},
)
}
return ZeroLog{}
}
type ZeroLog struct {
}
func (l ZeroLog) LogMode(logger.LogLevel) logger.Interface {
return l
}
func (l ZeroLog) Info(ctx context.Context, s string, values ...interface{}) {
logx.Infof(s, values...)
}
func (l ZeroLog) Warn(ctx context.Context, s string, values ...interface{}) {
logx.Errorf(s, values...)
}
func (l ZeroLog) Error(ctx context.Context, s string, values ...interface{}) {
logx.Errorf(s, values...)
}
func (l ZeroLog) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error) {
now := time.Now()
sql, rows := fc()
logx.Infof("[%v] [rows:%v] %s", now.Sub(begin).String(), rows, sql)
}
... ...