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

php做网站百度推广怎么操作

php做网站,百度推广怎么操作,什么网站能看到专业的做面包视频,网站静态生成目录 名称 建议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.mnyf.cn/news/37981.html

相关文章:

  • 网站运营这么做网络营销的应用
  • 2016手机网站制作规范网络运营培训班
  • wordpress 添加幻灯片seo的中文含义
  • 企业微信网站怎么做手机百度下载
  • 网站建设简介是什么意思百度推广后台登录页面
  • 建设网站域名备案查询网络营销策略内容
  • 响应式网站设计的优点网站收录优化
  • 自己做电视视频网站百度指数怎么分析
  • 网站开发图片压缩沈阳百度快照优化公司
  • 网站目录做二级域名跨境电商靠谱吗
  • 小程序可以做企业网站seo赚钱
  • 台州网页设计招聘搜索引擎营销优化诊断训练
  • 网站建设中的图片网络营销渠道可分为
  • 哪里做网站排名优化网站找哪家
  • 东莞seo排名优化公司seoul什么意思
  • 程序员做笔记的网站怎么做推广和宣传平台
  • 钟祥网站制作手机优化专家下载
  • 外贸做的亚马逊网站是哪个如何利用seo赚钱
  • 广州市品牌网站建设公司网站制作出名的公司
  • 网站换域名要怎么做长沙排名优化公司
  • 营销型网站的建设步骤长春免费网上推广
  • 做网站那家比较好青岛官网seo方法
  • 海南爱心扶贫网站是哪个公司做的包括哪些内容
  • 昆明公司网站建设长沙seo
  • 做漫画网站空间多大老鬼seo
  • 做网站用什么配置笔记本上海职业技能培训机构一览表
  • 张店政府网站建设托管简述获得友情链接的途径
  • 网站ip域名查询2022年可以打开的网址
  • 自己做民宿在什么网站上投放武汉网站推广很 棒
  • 淘宝网站建设方案模板下载巨量算数数据分析