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

个人如何做购物网站 关于支付接口东莞网络营销师培训学校

个人如何做购物网站 关于支付接口,东莞网络营销师培训学校,网站设计图能用ps做么,制作花灯第一章节 GoFrame 是一款基础设施建设比较完善的模块化框架 GoFrame 是一款基础设施建设比较完善的模块化框架, Web Server 模块是其中比较核心的模块,我们这里将 Web 服务开发作为框架入门的选择,便于大家更容易学习和理解。 用GOland编写代码 go.mod module goframePro…

第一章节 GoFrame

是一款基础设施建设比较完善的模块化框架

GoFrame 是一款基础设施建设比较完善的模块化框架, Web Server 模块是其中比较核心的模块,我们这里将 Web 服务开发作为框架入门的选择,便于大家更容易学习和理解。

用GOland编写代码

go.mod

module goframeProjectgo 1.24require github.com/gogf/gf/v2 v2.9.0require (github.com/BurntSushi/toml v1.4.0 // indirectgithub.com/clbanning/mxj/v2 v2.7.0 // indirectgithub.com/emirpasic/gods v1.18.1 // indirectgithub.com/fatih/color v1.18.0 // indirectgithub.com/fsnotify/fsnotify v1.7.0 // indirectgithub.com/go-logr/logr v1.4.2 // indirectgithub.com/go-logr/stdr v1.2.2 // indirectgithub.com/google/uuid v1.6.0 // indirectgithub.com/gorilla/websocket v1.5.3 // indirectgithub.com/grokify/html-strip-tags-go v0.1.0 // indirectgithub.com/kr/text v0.2.0 // indirectgithub.com/magiconair/properties v1.8.9 // indirectgithub.com/mattn/go-colorable v0.1.13 // indirectgithub.com/mattn/go-isatty v0.0.20 // indirectgithub.com/mattn/go-runewidth v0.0.16 // indirectgithub.com/olekukonko/tablewriter v0.0.5 // indirectgithub.com/rivo/uniseg v0.4.7 // indirectgo.opentelemetry.io/otel v1.32.0 // indirectgo.opentelemetry.io/otel/metric v1.32.0 // indirectgo.opentelemetry.io/otel/sdk v1.32.0 // indirectgo.opentelemetry.io/otel/trace v1.32.0 // indirectgolang.org/x/net v0.32.0 // indirectgolang.org/x/sys v0.28.0 // indirectgolang.org/x/text v0.21.0 // indirectgopkg.in/yaml.v3 v3.0.1 // indirect
)

我们先来开发一个简单的Web Server程序。

  • 新建main.go文件

    main.go

    package mainimport ("github.com/gogf/gf/v2/frame/g""github.com/gogf/gf/v2/net/ghttp"
    )func main() {s := g.Server()s.BindHandler("/", func(r *ghttp.Request) {r.Response.Write("Hello World Use goframeV2!")})s.SetPort(8000) //如果端口冲突,可以修改一下端口地址8088等s.Run()
    }
    

  • 配置go mod并安装依赖
    go mod init main
    go mod tidy
    

     可以看出执行后会进行下载依赖

  • go mod init main
    go: D:\GolandProjects\goframeProject\go.mod already existsD:\GolandProjects\goframeProject>go mod tidy
    go: downloading github.com/fatih/color v1.18.0
    go: downloading go.opentelemetry.io/otel v1.32.0
    go: downloading github.com/gorilla/websocket v1.5.3
    go: downloading go.opentelemetry.io/otel/trace v1.32.0
    go: downloading github.com/olekukonko/tablewriter v0.0.5
    go: downloading golang.org/x/net v0.32.0
    go: downloading github.com/grokify/html-strip-tags-go v0.1.0
    go: downloading go.opentelemetry.io/otel/sdk v1.32.0
    go: downloading github.com/emirpasic/gods v1.18.1
    go: downloading github.com/clbanning/mxj/v2 v2.7.0
    go: downloading github.com/fsnotify/fsnotify v1.7.0
    go: downloading github.com/mattn/go-colorable v0.1.13
    go: downloading golang.org/x/sys v0.28.0
    go: downloading github.com/mattn/go-runewidth v0.0.16
    go: downloading github.com/rogpeppe/go-internal v1.13.1
    go: downloading github.com/rivo/uniseg v0.4.7
    go: downloading go.opentelemetry.io/otel/metric v1.32.0
    go: downloading github.com/go-logr/logr v1.4.2
    go: downloading github.com/go-logr/stdr v1.2.2
    go: finding module for package github.com/kr/text
    go: found github.com/kr/text in github.com/kr/text v0.2.0
    

我们来看看这段代码:

  • 任何时候,您都可以通过 g.Server() 方法获得一个默认的 Server 对象,该方法采用单例模式设计, 也就是说,多次调用该方法,返回的是同一个 Server 对象。其中的g组件是框架提供的一个耦合组件,封装和初始化一些常用的组件对象,为业务项目提供便捷化的使用方式。
  • 通过Server对象的BindHandler方法绑定路由以及路由函数。在本示例中,我们绑定了/路由,并指定路由函数返回Hello World
  • 在路由函数中,输入参数为当前请求对象r *ghttp.Request,该对象包含当前请求的上下文信息。在本示例中,我们通过r.Response返回对象直接Write返回结果信息。
  • 通过SetPort方法设置当前Server监听端口。在本示例中,我们监听8000端口,如果在没有设置端口的情况下,它默认会监听一个随机的端口。
  • 通过 Run() 方法阻塞执行 Server 的监听运行。

执行结果​

运行该程序,您将在终端看到类似以下日志信息:

windows环境会提示需要访问外网。点击确定就OK。

$ go run main.go
2024-10-27 21:30:39.412 [INFO] pid[58889]: http server started listening on [:8000]
2024-10-27 21:30:39.412 [INFO] {08a0b0086e5202184111100658330800} openapi specification is disabledADDRESS | METHOD | ROUTE |     HANDLER     | MIDDLEWARE  
----------|--------|-------|-----------------|-------------:8000   | ALL    | /     | main.main.func1 |             
----------|--------|-------|-----------------|-------------

在默认的日志打印中包含以下信息:

  • 当前进程号58889,以及监听的地址:8000(表示监听本机所有IP地址的8000端口)。

  • 由于框架带有自动接口文档生成功能,本示例中未启用,因此提示openapi specification is disabled。 关于接口文档的自动生成,在开发手册中对应章节会详细讲解,本示例不作介绍。

  • 最后会打印当前Server的路由列表。由于我们只监听了/路由,那么这里只打印了一个路由信息。在路由信息表中:

    路由字段字段描述
    ADDRESS表示该路由的监听地址,同一个进程可以同时运行多个Server,不同的Server可以监听不同的地址。
    METHOD表示路由监听的HTTP Method信息,比如GET/POST/PUT/DELETE等。这里的ALL标识监听所有的HTTP Method
    ROUTE表示监听的具体路由地址信息。
    HANDLER表示路由函数的名称。由于本示例使用的是闭包函数,因此看到的是一个临时函数名称main.main.func1
    MIDDLEWARE表示绑定到当前路由的中间件函数名称,中间件是Server中一种经典的拦截器,后续章节中会有详细讲解,这里暂不做介绍。

运行后,我们尝试访问 <

http://www.dtcms.com/wzjs/835352.html

相关文章:

  • 自己建网站开网店建设考试网站首页
  • 网站设计示例怎么建php网站
  • 网站搬迁苏州网页制作与设计
  • 网站管理规划方案沈阳头条新闻
  • 如何说服企业做网站网页设计毕业设计开题报告
  • 洛阳网站建站云南网站做的好的公司哪家好
  • 平台网站建设协议建立网站的基本流程有哪些步骤
  • 广告发布包括哪些关于seo关键词选择有哪些方法
  • 网站 内容 营销沧州网站推广优化
  • 有域名怎么做公司网站wordpress 4.1分页
  • 什么是自适应网站优化步骤
  • 网站腾讯备案吗国家信息公示系统官网
  • 旅游论坛网站建设网站建设的目的与意义是什么意思
  • 个人域名备案做企业网站最新国际军事新闻
  • 网站建设的客户在哪里定制系统软件开发
  • 个人网站建设方案模板建站工具哪个好用
  • 仿做网站要多少钱seo优化包括哪些内容
  • 成都flash互动网站开发免费链接转换短网址
  • 正规的企业网站建设公司深圳西乡建网站
  • 做销售的 都有什么网站一个人可以建设几个网站
  • 网站运营团队管理广州广告公司
  • 书写网站建设策划书wordpress 内页打不开
  • 南京地区网站开发房产网名字叫啥好听
  • 学校网站怎么做的好处wordpress有中文版没
  • 深圳建站网站网站公司天津网站开发价格
  • 有没有做家具特卖的网站网站网站建设网站
  • 佛山做外贸网站如何怎么开店
  • 上海创意型网站建设姑苏区住房和建设局网站
  • 网站浮动窗口怎么设置国际网站怎么做
  • 爱墙 网站怎么做网站用模板为什么不利于seo推广