当前位置: 首页 > news >正文

做网站 传视频 用什么笔记本好开封seo公司

做网站 传视频 用什么笔记本好,开封seo公司,wix怎么做网页,建立网站的技术Gpt微信小程序搭建的前后端流程 - 后端基础框架的搭建(三) Gpt微信小程序 只需要几个API,API上一小节也有讲到。直接用 gin 或者 beego 简单搭web服务器就够了。我们这里还用 go-micro微服务 去搭建,主要也是为了学以致用,把之前go-micro系列…

Gpt微信小程序搭建的前后端流程 - 后端基础框架的搭建(三)


Gpt微信小程序 只需要几个API,API上一小节也有讲到。直接用 gin 或者 beego 简单搭web服务器就够了。我们这里还用 go-micro微服务 去搭建,主要也是为了学以致用,把之前go-micro系列播客衔接上,以及后续好的横纵向扩展。


整体的代码框架:

图1

pkg通用库中用到的db数据库,redis和mq队列,大部分都是前面go-micro系列有用到的。internal内部的微服务目录也是在之前go-micro单个微服务目录格式上调整。

这里主要看配置解析, 配置解析用得是toml库, github.com/BurntSushi/toml


pkg目录

图2

配置的代码解析,用一个接口(基类) IConfig

pkg/config/config.go

type IConfig interface {//服务名AppName() string//运行模式AppEnv() string//日志的定义LogFilePath() stringLogMaxAge() intLogMaxSize() intLogBackUpNum() int//mysql关系型数据库SchemeConfig() map[string]*SchemeConfig//redisRedisConfig() map[string]*RedisConfig//rabbitmqAmqpConfig() map[string]*AmqpConfig
}// log日志库基本配置
type LogConfig struct {Type         string `yaml:"Type",toml:"Type"`LogDir       string `yaml:"LogDir",toml:"LogDir"`LogName      string `yaml:"LogName",toml:"LogName"`LogMaxAge    int    `yaml:"LogMaxAge",toml:"LogMaxAge"`       // 日志的过期时间,单位为天LogMaxSize   int    `yaml:"LogMaxSize",toml:"LogMaxSize"`     // 日志文件的最大LogBackUpNum int    `yaml:"LogBackUpNum",toml:"LogBackUpNum"` // 日志文件最多保留个数}// 服务配置
type Config struct {ConfPath string                   //配置路径AppPath  string                   //项目路径Scheme   map[string]*SchemeConfig `yaml:"Scheme",toml:"Scheme"`Redis    map[string]*RedisConfig  `yaml:"Redis",toml:"Redis"`Amqp     map[string]*AmqpConfig   `yaml:"Amqp",toml:"Amqp"`Log      *LogConfig               `yaml:"Log",toml:"Log"`
}// App 的基本配置
type AppBaseConfig struct {AppName string `yaml:"AppName",toml:"AppName"`Env     string `yaml:"Env",toml:"Env"`Version string `yaml:"Version",toml:"Version"` // 版本
}type AppConfig struct {ConfigApp AppBaseConfig
}

pkg/config/scheme.go

// 关系型数据库的配置
type SchemeConfig struct {// mysql pgsqlDriver string `yaml:"Driver",toml:"Driver"`Dsn string `yaml:"Dsn",toml:"Dsn"`// 建立最大的连接数MaxOpenConns int `yaml:"MaxOpenConns",toml:"MaxOpenConns"`// 最大的空闲连接数MaxIdleConns int `yaml:"MaxIdleConns",toml:"MaxIdleConns"`// 一条连接存活的最长时间ConnMaxLifeTime int `yaml:"ConnMaxLifeTime",toml:"ConnMaxLifeTime"`
}

pkg/config/redis.go

// redis配置
type RedisConfig struct {Addr        string `yaml:"Addr",toml:"Addr"` // host:portPassword    string `yaml:"Password",toml:"Password"`MaxConnNum  int    `yaml:"MaxConnNum",toml:"MaxConnNum"`InitConnNum int    `yaml:"InitConnNum",toml:"InitConnNum"`IdleTimeout int    `yaml:"IdleTimeout",toml:"IdleTimeout"`PingStep    int    `yaml:"PingStep",toml:"PingStep"`RetryTimes  int    `yaml:"RetryTimes",toml:"RetryTimes"`
}

pkg/config/amqp.go

// rabbitmq
type AmqpConfig struct {Addr string `toml:"Addr"`Port int `toml:"Port"`User string `toml:"User"`Pwd string `toml:"Pwd"`MaxConnection int `toml:"MaxConnection"`MaxChannel int `toml:"MaxChannel"`VirtualHost string `toml:"VirtualHost"`Type int `toml:"Type"`
}

对应的toml配置格式:
config/test_service/app.toml

[App]AppName = "test_service"Version = "1.0"Env = "dev"[Log]Type = "log"             # 默认是log, 可以是redis, kafka获取是其他的,如果是其他的请在 log中实现LogDir = "/log"LogName = "error_log.log"LogMaxAge = 7            # 单位 day,日志最多可以保存多长时间。只有 Type 为File时才会有效LogMaxSize = 10          # 文件大小(M),10MLogBackUpNum = 10        # 文件保留最多个数[Scheme]# 放置数据库连接信息[Scheme.base]Driver = "mysql"Dsn = "root:root@tcp(127.0.0.1:3306)/test?charset=utf8mb4&parseTime=true"MaxOpenConns = 60MaxIdleConns = 20ConnMaxLifeTime = 1200[Redis][Redis.base]Addr = "127.0.0.1:6379"Password = "11111111"MaxConnNum = 20InitConnNum = 1IdleTimeout = 7200      #最大idle时间PingStep = 10           #两次ping之间间隔RetryTimes = 3          #获取连接重试次数[Amqp][Amqp.publish]Addr = "127.0.0.1"Port = 5672User = "guest"Pwd = "guest"MaxConnection = 4VirtualHost = "/"Type = 1                # 1生产者;2消费者[Amqp.consume]Addr = "127.0.0.1"Port = 5672User = "guest"Pwd = "guest"MaxConnection = 10MaxChannel = 10VirtualHost = "/"Type = 2                # 1生产者;2消费者

最后的配置解析
pkg/config/parse.go

// 解析配置
func ParseConfig() {verifyConf()toml.DecodeFile(Conf.ConfPath, Conf)
}func verifyConf() {if fl, err := os.Stat(Conf.ConfPath); err != nil {if os.IsNotExist(err) {fmt.Println(Conf.ConfPath)fmt.Printf("config file %s not exists", Conf.ConfPath)os.Exit(0)}} else {fl.Mode().Perm()}
}// 获取项目当前路径
func getRunPath() string {rst, err := os.Getwd()if err != nil {return ""}return rst
}

这里,通用log日志库,mysql,redis,rabbitmq的配置解析和初始代码就好了,接下来就是微服务的初始化调用和启动了。


微服务目录
图3

微服务初始化代码, init.goelog.go

internal/test_service/init.go

// 服务
type EmicroService struct {Server micro.ServiceHost   stringPort   uintAddr   string
}// 服务的自定义配置
type ServerConfig struct {ServerLog   map[string]*config.LogConfig
}// 服务内部配置
type Conf struct {Config       *config.AppConfig  //pkg通用配置ServerConfig *ServerConfig
}// 服务操作对象
var Service *EmicroService// 日志库操作对象,对pkg的日志再封装
var Logger *zap.Logger// 服务内部配置操作对象
var Config *Conffunc init() {Service = NewService()Config = NewConfig()
}func NewService() *EmicroService {service := new(EmicroService)return service
}func NewConfig() *Conf {return new(Conf)
}// 初始化
func Init(confPath string) {//指定配置文件路径config.Conf.ConfPath = confPath//解析配置config.ParseConfig()// 处理日志文件路径和日志等级config.Conf.Log.LogDir = config.Conf.GetAppPath() + config.Conf.Log.LogDir + "/" + config.Conf.AppName()// 默认日志等级为errorvar level stringif config.Conf.AppEnv() == "dev" {level = "debug"} else {level = "error"}// 初始化通用日志库logObj.LoggerInit(config.Conf, level)Logger = logObj.Logger()// 初始数据库,Redis等database.Init(config.Conf)// 解析服务内部自定义配置Config.Config = config.Configer()var serverConf = new(ServerConfig)serverConfPath := Config.Config.GetAppPath() + "/internal/test_service/config/server.toml"toml.DecodeFile(serverConfPath, serverConf)Config.ServerConfig = serverConf// 初始化自定义的loginitServerLog(level)
}

internal/test_service/elog.go

// 服务自定义的log日志库操作对象
var ServerLogger map[string]*zap.Logger
var logLevel string// 初始化自定义的log
func initServerLog(level string){ServerLogger = make(map[string]*zap.Logger, len(Config.ServerConfig.ServerLog))logLevel = levelfor logName, logInfo := range Config.ServerConfig.ServerLog{logInfo.LogDir = config.Conf.AppPath + logInfo.LogDir + string(os.PathSeparator) +logNamelog, err := newServerLog(logInfo)if err != nil{panic("init server log err:" + err.Error())}ServerLogger[logName] = log}
}func newServerLog(logInfo *config.LogConfig) (*zap.Logger, error){var console boolif Config.Config.AppEnv() == "dev" {console = true}else{console = false}logInfo.LogName = getLogFilename()return logObj.CreateLogger(logLevel, console, logInfo)
}func getLogFilename() string {currentTime := time.Now()return currentTime.Format("2006-01-02") + ".log"
}

启动代码在internal/test_service/server/server.go,跟之前go-micro系列播客的微服务启动一样,这里不再列明。

启动脚本: cmd/test_service/main.go

package mainimport("emicro-go-base/internal/test_service/server"
)func main() {server.RunTestService(":8080", "../../config/test_service/app.toml")
}

后端基础的框架就大概这样,一些太细的细节代码就没全贴出来了,后续具体实现API章节会再继续贴

最后

可以先体验如下的微信小程序,该专栏系列都是参考小柠AI智能聊天来展开,小程序整体的gpt交互直接,界面也容易,对我们上手仿照在实现方面也比较友好。

体验方式:

  1. 微信小程序直接搜小柠AI智能聊天
  2. 扫码下图
    小柠AI智能聊天
http://www.hkea.cn/news/424977/

相关文章:

  • 株洲企业网站建设品牌2023免费b站推广大全
  • 仿制单页面网站多少钱免费制作网站app
  • 商城网站制作网站长尾词挖掘工具
  • 夹克定制公司trinseo公司
  • 四川智能网站建设制作网站链接分析工具
  • 制作销售网站有哪些宁波网络营销推广咨询报价
  • 佛山做外贸网站服务新闻发稿平台
  • 做网站前怎么写文档域名收录
  • 中信建设有限责任公司钟宁关键词优化的方法有哪些
  • 建站之星平台优化推广网站排名
  • wordpress 网盘 插件郑州seo外包阿亮
  • 怎样建设网站首页广告营销平台
  • wordpress调起淘宝app什么叫做seo
  • 嘉兴做网站优化的公司网站维护公司
  • css层叠样式会不会影响打开网站的速度百度免费下载安装百度
  • 网站模板制作流程nba交易最新消息汇总
  • 近的网站在线客服系统网络优化工程师前景如何
  • 网站制作职业google入口
  • 广州网站 制作信科便宜网络营销软文范例500
  • 网站建设公开课长沙网站推广和优化
  • 建设网站的需求分析俄罗斯搜索引擎yandex推广入口
  • 可以做英文纵横字谜的网站搜狗网站收录入口
  • web前端开发是不是做网站百家号关键词排名优化
  • 夸克看网站要钱吗电商网站seo优化
  • 自己做网站排版138ip查询网域名解析
  • 东莞做网站 南城石佳2023网站推广入口
  • 广东省省建设厅网站郴州网站建设网络推广平台
  • 校园网站推广方案怎么做应用商店优化
  • 巩义网站建设网络营销公司是做什么的
  • 做网站基本教程一站式营销平台