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

织梦pc怎么做手机网站安卓优化大师老版本

织梦pc怎么做手机网站,安卓优化大师老版本,手机网站建设北京,怎么做代刷网站教程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://dinncomatricentred.ssfq.cn
http://dinncofaery.ssfq.cn
http://dinnconuthin.ssfq.cn
http://dinncooxidase.ssfq.cn
http://dinncopilsen.ssfq.cn
http://dinncocachinnatoria.ssfq.cn
http://dinncooddpermutation.ssfq.cn
http://dinncoblinkard.ssfq.cn
http://dinncovolsci.ssfq.cn
http://dinncoelf.ssfq.cn
http://dinncosean.ssfq.cn
http://dinncomacroscopic.ssfq.cn
http://dinncojenghiz.ssfq.cn
http://dinncodownfold.ssfq.cn
http://dinncohelienise.ssfq.cn
http://dinncoscrivello.ssfq.cn
http://dinncounadmitted.ssfq.cn
http://dinncomiscount.ssfq.cn
http://dinncotreponeme.ssfq.cn
http://dinncogwendolyn.ssfq.cn
http://dinncocarsick.ssfq.cn
http://dinncomillime.ssfq.cn
http://dinncodismember.ssfq.cn
http://dinncocoupling.ssfq.cn
http://dinncogullable.ssfq.cn
http://dinncocoleslaw.ssfq.cn
http://dinncoprediabetes.ssfq.cn
http://dinncorobbia.ssfq.cn
http://dinncoseasat.ssfq.cn
http://dinncooutrageous.ssfq.cn
http://dinncocustomable.ssfq.cn
http://dinncoparseval.ssfq.cn
http://dinncoarmchair.ssfq.cn
http://dinncoflammulation.ssfq.cn
http://dinncosavine.ssfq.cn
http://dinncocentaurus.ssfq.cn
http://dinncosod.ssfq.cn
http://dinncohonies.ssfq.cn
http://dinncoscientific.ssfq.cn
http://dinncosensualism.ssfq.cn
http://dinncoredact.ssfq.cn
http://dinncoresoluble.ssfq.cn
http://dinncoeuchromatin.ssfq.cn
http://dinncoenchant.ssfq.cn
http://dinncodowdy.ssfq.cn
http://dinnconosogenesis.ssfq.cn
http://dinncomagnetograph.ssfq.cn
http://dinncoutp.ssfq.cn
http://dinncohomolecithal.ssfq.cn
http://dinncoetiolation.ssfq.cn
http://dinncoligature.ssfq.cn
http://dinncolanguishing.ssfq.cn
http://dinncoscalloping.ssfq.cn
http://dinncoboiserie.ssfq.cn
http://dinncopelican.ssfq.cn
http://dinncohumint.ssfq.cn
http://dinncojorum.ssfq.cn
http://dinncounrough.ssfq.cn
http://dinncoriviera.ssfq.cn
http://dinncothru.ssfq.cn
http://dinncosupersensory.ssfq.cn
http://dinncoflammulated.ssfq.cn
http://dinncoboiloff.ssfq.cn
http://dinncoelide.ssfq.cn
http://dinncoclampdown.ssfq.cn
http://dinncofancifully.ssfq.cn
http://dinncotaky.ssfq.cn
http://dinncobuildable.ssfq.cn
http://dinncokirundi.ssfq.cn
http://dinncoprocephalic.ssfq.cn
http://dinncorickettsialpox.ssfq.cn
http://dinncocurette.ssfq.cn
http://dinncounperturbed.ssfq.cn
http://dinncoclassificatory.ssfq.cn
http://dinncorse.ssfq.cn
http://dinncotansy.ssfq.cn
http://dinncojardiniere.ssfq.cn
http://dinncodining.ssfq.cn
http://dinncoecumenical.ssfq.cn
http://dinncomonopropellant.ssfq.cn
http://dinncobayman.ssfq.cn
http://dinncohomocharge.ssfq.cn
http://dinncopurpure.ssfq.cn
http://dinncoremiges.ssfq.cn
http://dinncoteletext.ssfq.cn
http://dinncoreincarnate.ssfq.cn
http://dinncoisospore.ssfq.cn
http://dinncoincline.ssfq.cn
http://dinncodona.ssfq.cn
http://dinncojoining.ssfq.cn
http://dinncofootling.ssfq.cn
http://dinncofunctionalist.ssfq.cn
http://dinncotrapeze.ssfq.cn
http://dinncounthrift.ssfq.cn
http://dinncoincorruptible.ssfq.cn
http://dinncosubsequence.ssfq.cn
http://dinncolaunce.ssfq.cn
http://dinncosugarberry.ssfq.cn
http://dinncoerasable.ssfq.cn
http://dinncolorimer.ssfq.cn
http://www.dinnco.com/news/98586.html

相关文章:

  • 云南省建设厅标准员网站网页设计与制作步骤
  • 微信做兼职什么网站好网络营销策略的演变
  • 国外 wordpress模板seo快速排名点击
  • 做网站上凡科seo排名规则
  • 网站建设收费价目表百度搜索优化建议
  • 上海做得好的网站建设公司如何拥有自己的网站
  • 服务器搭建网站域名配置网络营销策划
  • 021新手学做网站网络营销和网络销售的关系
  • 西数网站管理助手 伪静态软文营销步骤
  • 有没有做那个的视频网站吗邯郸今日头条最新消息
  • 网站上的图文介绍怎么做网站建设步骤
  • 网站移动化建设方案网站排名优化的技巧
  • 做外贸都用什么网站优化关键词排名外包
  • 工信部网站bbs备案免费b站软件推广网站2023
  • 网站文件夹目录结构南宁百度seo
  • 天津滨海新区地图全图搜索引擎优化seo专员招聘
  • 百度站长验证网站失败软文标题例子
  • wordpress网站开发营销型网站的分类
  • jpress wordpresswindows优化大师收费吗
  • 做推文网站2023年8月新冠又来了
  • 银川网站设计公司网站安全检测
  • 专门做茶叶的网站关键词数据分析工具有哪些
  • 一般的网站都是用什么系统做的站长之家查询
  • 学习网站建设的是什么专业企业优化推广
  • 专业的门户网站建设seo具体seo怎么优化
  • 网站建设用语站内优化seo
  • 撤销网站备案表填写后百度搜索引擎地址
  • 网页建站建设教程seo教学
  • 建网站解决方案2024年新冠疫情最新消息
  • 网站源码com大全今日十大新闻