从0开始学go 第一天

今天是开始学go的第x天,前些日子看了看语言,今天找一个web开发来跟着学,记录一下遇到的问题,方便以后复习查阅。

视频看的是https://www.bilibili.com/video/BV1gJ411p7xC?p=3&vd_source=ab5bdbd04f4142027c66d604d5285204

视频中用的是goland,我用的vs

如何在vs中建一个项目:

https://blog.csdn.net/sepnineth/article/details/125153354

这也是为了解决一个报错:

Go 复制代码
go.mod file not found in current directory or any parent directory.
        'go get' is no longer supported outside a module.
        To build and install a command, use 'go install' with a version,
        like 'go install example.com/cmd@latest'
        For more information, see https://golang.org/doc/go-get-install-deprecation
        or run 'go help get' or 'go help install'.

因为下载gin的时候会报错,就是这个命令:go get -u github.com/gin-gonic/gin

初次尝试go写一个网页还是挺有意思的

Go 复制代码
package main

import (
	"fmt"
	"net/http"
)

func sayHello(w http.ResponseWriter, r *http.Request) {
	_, _ = fmt.Fprintln(w, "Hello jzy")
}

func main() {
	http.HandleFunc("/hello", sayHello)
	err := http.ListenAndServe(":9090", nil)
	if err != nil {
		fmt.Printf("http server failed, err:%v\n", err)
		return
	}
}
相关推荐
漂亮的小碎步丶9 分钟前
【6】数据库事务与锁机制详解(附并发结算案例)
数据库·事务·锁机制
合方圆~小文18 分钟前
4G定焦球机摄像头综合介绍产品指南
数据结构·数据库·人工智能
zxrhhm20 分钟前
数据库中的COALESCE函数用于返回参数列表中第一个非NULL值,若所有参数均为NULL则返回NULL
数据库·postgresql·oracle
小学鸡!22 分钟前
DBeaver连接InfluxDB数据库
数据库
Yeniden26 分钟前
Deepeek用大白话讲解 --> 迭代器模式(企业级场景1,多种遍历方式2,隐藏集合结构3,Java集合框架4)
java·开发语言·迭代器模式
running up31 分钟前
MyBatis 核心知识点与实战
数据库·oracle·mybatis
SmoothSailingT35 分钟前
C#——LINQ方法
开发语言·c#·linq
景川呀36 分钟前
Java的类加载器
java·开发语言·java类加载器
薛不痒36 分钟前
MySQL中使用SQL语言
数据库·sql·mysql
k***921639 分钟前
Python 科学计算有哪些提高运算速度的技巧
开发语言·python