❤️💕💕Go语言的web框架gin框架、gorm基本使用以及web开发项目实战,更多请移步我的博客Myblog:http://nsddd.top
[TOC] #web #gin
- web是基于HTTP协议进行交互的应用网络
- web就是通过使用浏览器/APP访问的各种资源
浏览器请求 — 服务器响应
go语言的http库可以看文章
/*
* @Author: xiongxinwei 3293172751nss@gmail.com
* @Date: 2022-09-01 14:21:54
* @LastEditors: xiongxinwei 3293172751nss@gmail.com
* @LastEditTime: 2022-09-01 14:57:29
* @FilePath: \code\markdown\main.go
* @Description: go web 开发
*/
package main
import (
"fmt"
"net/http"
)
func sayHello(w http.ResponseWriter, r *http.Request) {
_, _ = fmt.Fprintln(w, "<h1>hello word<h1>")
//向文件中写入helloword
}
func main() {
http.HandleFunc("/hello", sayHello)
// 往浏览器写入hello这调用函数sayhello -- 如何访问或者启动这个服务
err := http.ListenAndServe(":9090", nil)
if err != nil {
fmt.Printf("http serve faile err = %v\n", err)
//遇到错误直接返回
return
}
}
基于一个共同的类型下,相同的方式进行返回
对于sayHello模块,我们可以使用方法从文件中读出
func sayHello(w http.ResponseWriter, r *http.Request) {
b, _ := ioutil.ReadFile("./hello.txt")
_, _ = fmt.Fprintln(w, string(b))
//向文件中写入helloword
}
可以在hello.txt中加入任何内容