Commit 9dec477a by mushishixian

接入配置包

parent d61559f9
package main
func main() {
import (
"bom_server/cmd/queue"
"bom_server/configs"
"flag"
)
func main() {
var path string
flag.StringVar(&path, "config", "../conf/config.ini", "../conf/config.ini")
flag.Parse()
configs.Setup(path)
queue.Sync()
}
package queue
import (
"bom_server/configs"
"fmt"
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
)
type RecvPro struct {
}
func (t *RecvPro) Consumer(dataByte []byte) error {
return nil
}
func (t *RecvPro) FailAction(dataByte []byte) error {
fmt.Println("任务处理失败了,发送钉钉消息通知主人")
return nil
}
func Sync() {
t := &RecvPro{}
rabbitmq.Recv(rabbitmq.QueueExchange{
"bom_match",
"bom_match",
"bom",
"direct",
configs.RabbitMQSetting.Url,
}, t, 1)
}
package queue
\ No newline at end of file
[mysql]
[database]
username = root
password = root
host = 192.168.2.250
......
package configs
import (
"fmt"
"github.com/go-ini/ini"
"log"
"time"
)
type Server struct {
RunMode string
HttpPort int
ReadTimeout time.Duration
WriteTimeout time.Duration
}
type Database struct {
Type string `ini:"type"`
UserName string `ini:"user_name"`
Password string `ini:"password"`
Host string `ini:"host"`
Database string `ini:"database"`
TablePrefix string `ini:"table_prefix"`
}
type Redis struct {
Host string `ini:"host"`
Password string `ini:"password"`
MaxIdle int `ini:"max_idle"`
MaxActive int `ini:"max_active"`
IdleTimeout time.Duration `ini:"idle_timeout"`
}
type RabbitMQ struct {
Url string `ini:"url"`
}
var DatabaseSetting = &Database{}
var RedisSetting = &Redis{}
var RabbitMQSetting = &RabbitMQ{}
var (
cfg *ini.File
)
// Setup initialize the configuration instance
func Setup(filePath string) {
var err error
cfg, err = ini.Load(filePath)
if err != nil {
panic(fmt.Sprintf("解析配置文件失败: %v", err))
}
mapTo("database", DatabaseSetting)
mapTo("redis", RedisSetting)
mapTo("rabbitmq", RabbitMQSetting)
RedisSetting.IdleTimeout = RedisSetting.IdleTimeout * time.Second
}
// mapTo map section
func mapTo(section string, v interface{}) {
err := cfg.Section(section).MapTo(v)
if err != nil {
log.Fatalf("Cfg.MapTo %s err: %v", section, err)
}
}
package configs
type DbInfo struct {
Engine string
User string
Pass string
Ip string
Port string
Table string
}
//func GetDBOne() DbInfo {
// return DbInfo{
// "mysql",
// "root",
// "root",
// "192.168.2.250",
// "3306",
// "lie_scm_sync",
// }
//}
func GetDBOne() DbInfo {
return DbInfo{
"mysql",
DatabaseSetting.UserName,
DatabaseSetting.Password,
DatabaseSetting.Host,
"3306",
DatabaseSetting.Database,
}
}
func GetDBCms() DbInfo {
return DbInfo{
"mysql",
"ichuntcms",
"ichuntcms#zsyM",
"192.168.2.232",
"3306",
"ichuntcms",
}
}
func GetDBLiexin() DbInfo {
return DbInfo{
"mysql",
"liexin",
"liexin#zsyM",
"192.168.2.232",
"3306",
"liexin",
}
}
module bom_server
go 1.13
require (
github.com/beevik/etree v1.1.0
github.com/go-ini/ini v1.56.0
github.com/go-kratos/kratos v0.5.0
github.com/ichunt2019/go-rabbitmq v1.0.1
github.com/imroc/req v0.3.0
github.com/jmoiron/sqlx v1.2.0
github.com/mushishixian/gosoap v1.2.0
github.com/pkg/errors v0.9.1
github.com/smartystreets/goconvey v1.6.4 // indirect
gopkg.in/ini.v1 v1.56.0 // indirect
)
This diff is collapsed. Click to expand it.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment