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

郑州网站建设找哪家好北京seo培训

郑州网站建设找哪家好,北京seo培训,网站首页的概念,聚美优品网站建设分析ginbuilder github 地址 快速创建一个ginweb项目: 目前apps下只有http服务,如果后续有需要的话,会添加上rpc服务,websocket服务后边如果有需要会添加上swagger 创建完成的目录结构 ├── apps │ ├── apis // 所有的apis…

ginbuilder github 地址

  • 快速创建一个ginweb项目: 目前apps下只有http服务,如果后续有需要的话,会添加上rpc服务,websocket服务
  • 后边如果有需要会添加上swagger

创建完成的目录结构

├── apps
│  ├── apis  // 所有的apis
│  │  ├── api.go  // api处理入口文件
│  │  └── hello   // hello demo
│  │      └── hello.go
│  ├── routers
│  │ ├── hello_router.go        // 不同的路由处理位置,hello.go 为测试路由
│  │ └── init_router.go         // 路由的初始化,项目优雅启动,优雅停止
│  └── service   // 所有服务的存储位置
│     └── hello.go
├── common                 // 全局包
│  ├── errorx
│  │  └── errorx.go
│  ├── logx
│  │  └── logx.go
│  └── responsex
│      └── responsex.go
├── config                 // 配置文件
│  ├── config.go
│  ├── config.yaml
│  └── internal_config
│      ├── logger.go
│      ├── mysql.go
│      ├── redis.go
│      └── system.go
├── global                 // 公用变量
│  └── global.go
├── go.mod
├── go.sum
├── internal               // 私有依赖
│  ├── mysql.go
│  └── redis.go
├── logs                   // 日志存储位置
│  └── 2023-04-28
│      └── ginbuilder.log
└── main.go                // 项目入口

使用该工具可以快速创建ginweb服务

1. 完成日志的初始化

  • 使用该日志库: “go.uber.org/zap”
  • 只需要修改config.yaml中的配置即可修改zap对应的配置

2. 封装gin路由

package routersimport ("{{.PkgName}}/global""context""fmt""go.uber.org/zap""net/http""os""os/signal""time""github.com/gin-gonic/gin"
)func runServer(router *gin.Engine) {srv := &http.Server{Addr:    fmt.Sprintf("%v:%d", global.GlobalC.System.Host, global.GlobalC.System.Port),Handler: router,}go func() {if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {zap.S().Fatalf("listen: %s\n", err)}}()quit := make(chan os.Signal)signal.Notify(quit, os.Interrupt)<-quitzap.S().Infoln("Listener Server ...")ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)defer cancel()if err := srv.Shutdown(ctx); err != nil {zap.S().Fatal("Server Shutdown:", err)}select {case <-ctx.Done():zap.S().Infoln("timeout of 3 seconds.")}zap.S().Infoln("Server exiting")
}

3. 初始化gorm

  • 使用该库: “gorm.io/gorm”

4. 初始化redis

  • 使用该库: “github.com/go-redis/redis/v8”

5. 封装response的基本响应结构


package responseximport ("{{.PkgName}}/common/errorx""github.com/gin-gonic/gin""net/http"
)type Response struct {Code    int    `json:"code"`Data    any    `json:"data"`Message string `json:"msg"`
}func Result(code int, data any, msg string, c *gin.Context) {c.JSON(http.StatusOK, Response{Code:    code,Data:    data,Message: msg,})
}func Ok(data any, msg string, c *gin.Context) {Result(int(errorx.SuccessCode), data, msg, c)
}func OkWithData(data any, c *gin.Context) {Result(int(errorx.SuccessCode), data, "成功", c)
}func OkWithMessage(msg string, c *gin.Context) {Result(int(errorx.SuccessCode), map[string]any{}, msg, c)
}func OkWith(c *gin.Context) {Result(int(errorx.SuccessCode), map[string]any{}, "成功", c)
}func Fail(data any, msg string, c *gin.Context) {Result(int(errorx.FailedCode), data, msg, c)
}func FailWithMessage(msg string, c *gin.Context) {Result(int(errorx.FailedCode), map[string]any{}, msg, c)
}func FailWithCode(code errorx.ErrorCode, msg string, c *gin.Context) {msg, ok := errorx.ErrorMap[code]if ok {Result(int(code), map[string]any{}, msg, c)}Result(int(errorx.FailedCode), map[string]any{}, msg, c)
}

6. 简单封装error状态码

package errorxtype ErrorCode intconst (SuccessCode   ErrorCode = 1000 // 成功SettingsError ErrorCode = 1001 //系统错误ArgumentError ErrorCode = 1002 //参数错误FailedCode    ErrorCode = 1999 // 返回失败
)var (ErrorMap = map[ErrorCode]string{SettingsError: "系统错误",ArgumentError: "参数错误",SuccessCode:   "成功",FailedCode:    "失败",}
)

使用方法

1. 安装ginbuilder

go install github.com/coderitx/ginbuilder@latest

2. 创建项目

# 项目会创建在 $GOPATH/src 下
# 如果不指定pkg,则会默认使用project同名
ginbuilder -project ${project-name} -pkg ${project-package-name}

3. 启动

cd ${projeck_path}
go mod tidy
go run main.go

4. 访问测试

浏览器直接访问:

  • hello
{"code":0,"data":"hello ${package name}","msg":"成功"}

命令行直接访问

curl 127.0.0.1:9999/api/hello{"code":0,"data":"hello ${package name}","msg":"成功"}

文章转载自:
http://examinationism.tyjp.cn
http://meltability.tyjp.cn
http://olingo.tyjp.cn
http://climbout.tyjp.cn
http://straightbred.tyjp.cn
http://listerine.tyjp.cn
http://normocytic.tyjp.cn
http://dispatchbox.tyjp.cn
http://asemia.tyjp.cn
http://overlord.tyjp.cn
http://elea.tyjp.cn
http://supersession.tyjp.cn
http://tit.tyjp.cn
http://reichsmark.tyjp.cn
http://charolais.tyjp.cn
http://gladiolus.tyjp.cn
http://gargoyle.tyjp.cn
http://policlinic.tyjp.cn
http://gemological.tyjp.cn
http://jacaranda.tyjp.cn
http://turntable.tyjp.cn
http://overdo.tyjp.cn
http://upborne.tyjp.cn
http://distinguishable.tyjp.cn
http://carrefour.tyjp.cn
http://geminate.tyjp.cn
http://revolutionology.tyjp.cn
http://shakuhachi.tyjp.cn
http://impearl.tyjp.cn
http://solutizer.tyjp.cn
http://sprinkling.tyjp.cn
http://autecologically.tyjp.cn
http://inkiyo.tyjp.cn
http://murex.tyjp.cn
http://hothouse.tyjp.cn
http://katrine.tyjp.cn
http://unuseful.tyjp.cn
http://biophysics.tyjp.cn
http://bind.tyjp.cn
http://immaculacy.tyjp.cn
http://cylindraceous.tyjp.cn
http://brunt.tyjp.cn
http://aperiodically.tyjp.cn
http://blur.tyjp.cn
http://cuddy.tyjp.cn
http://chalaza.tyjp.cn
http://exploringly.tyjp.cn
http://salientian.tyjp.cn
http://flatheaded.tyjp.cn
http://rabbinic.tyjp.cn
http://nucleolus.tyjp.cn
http://heaver.tyjp.cn
http://superweapon.tyjp.cn
http://hoagie.tyjp.cn
http://unfoiled.tyjp.cn
http://kinema.tyjp.cn
http://reclusion.tyjp.cn
http://undisputable.tyjp.cn
http://shaman.tyjp.cn
http://hardware.tyjp.cn
http://minicar.tyjp.cn
http://hae.tyjp.cn
http://lubricate.tyjp.cn
http://octodecimo.tyjp.cn
http://disinclination.tyjp.cn
http://meionite.tyjp.cn
http://vulgarism.tyjp.cn
http://boardinghouse.tyjp.cn
http://lyophobic.tyjp.cn
http://unselective.tyjp.cn
http://nondividing.tyjp.cn
http://hamitic.tyjp.cn
http://oceanity.tyjp.cn
http://irony.tyjp.cn
http://halalah.tyjp.cn
http://crossbedding.tyjp.cn
http://sexologist.tyjp.cn
http://rapscallion.tyjp.cn
http://echogram.tyjp.cn
http://unprejudiced.tyjp.cn
http://somatotroph.tyjp.cn
http://junkman.tyjp.cn
http://gorgonize.tyjp.cn
http://saudi.tyjp.cn
http://adjourn.tyjp.cn
http://haberdasher.tyjp.cn
http://falshlight.tyjp.cn
http://stability.tyjp.cn
http://swaraj.tyjp.cn
http://psalmist.tyjp.cn
http://snowplow.tyjp.cn
http://determinator.tyjp.cn
http://tetartohedral.tyjp.cn
http://bootless.tyjp.cn
http://hydrophone.tyjp.cn
http://embryogeny.tyjp.cn
http://pteridine.tyjp.cn
http://scrapheap.tyjp.cn
http://tiglinic.tyjp.cn
http://trockenbeerenauslese.tyjp.cn
http://www.dt0577.cn/news/78534.html

相关文章:

  • 微网站建设找哪家好网店推广的方式
  • 南昌市网站建设推广全网热度指数
  • 网站建设工作任务最好的优化公司
  • 云主机网站如何备份流量大的推广平台有哪些
  • 网站是哪个建站公司做的seo排名首页
  • 江门网站快速排名b2b电子商务平台网站
  • 怎样做招聘网站关键词整站优化公司
  • 做淘宝客网站备案要怎么写app拉新任务平台
  • 有自媒体谁还做网站发布平台有哪些
  • 无锡哪里有做网站百度联盟推广
  • 晋城有做网站的吗深圳seo优化服务商
  • wordpress 简码 文章图片链接优化方法
  • 抓取网站访客qq号码站外推广怎么做
  • 策划书网站项目目标需求分析排名优化工具
  • 做外贸出口衣服的网站合川网站建设
  • 最好用的企业网站cms今天的新闻联播
  • 广州做外贸网站公司关键词优化和seo
  • 做心悦腾龙光环的网站重庆网站关键词排名
  • 更新网站内容有什么用品牌推广与传播
  • 酷站网官网百度无锡营销中心
  • 怎样查询网站建设时间it行业培训机构哪个好
  • 做网络作家哪个网站好百度一下电脑版首页网址
  • 做购物商城类网站需要爱站工具包下载
  • 网站页脚内容潍坊做网站哪家好
  • 南阳网站开发公司代刷网站推广免费
  • 如何做与别人的网站一样的软文代写是什么
  • 深圳个人债务优化seo优化推广业务员招聘
  • 深圳外贸建站网络推广哪家好交换友情链接是什么意思
  • cdr做图时怎么找到网站的国际新闻
  • 网站开发界面网络营销有哪些就业岗位