[Building]Use Go & Vue3 to build an easy blog

Go + Vue3 Study

环境安装

本地环境:Go 1.17

后端框架:Gin

注意Go在使用Go Module的话需要使用修改Go的代理

首先查看Go相关的环境变量

go env

修改Go代理

go env -w Go111MODULE=on

go env -w GOPROXY=https://goproxy.cn,direct

后端框架

Gin

框架下载

go get -u github.com/gin-gonic/gin

这里注意代理一定要配置好否则下载会非常慢

框架引入

实例代码如下所示:

package main

import ("github.com/gin-gonic/gin")

func main() {
	r := gin.Default()
	r.GET("/ping", func(c *gin.Context) {
		c.JSON(200, gin.H{"msg": "pong"})
	})

	r.Run() // listen and serve on 0.0.0.0:8080
}

首先通过import语句引入相关的包

在main函数中,初始化一个gin类型,对于一个GET请求,返回一个status是200且内容是{"msg": "pong"}的信息

最后开启该项目,默认在localhost:8080启动

使用POSTMAN进行测试

这里简单介绍一下GETPOST请求的区别:

GET请求是把参数放在URL中的一种TCP/IP协议,在进行传输时只进行一次传输。一般来说服务器会对GET请求的大小进行限制

POST请求是把参数放到Request Body中传输,在进行传输过程中会进行两次传输。一般对于POST的大小限制会弱于GET的大小限制

框架语法

H: Gin中的一个语法,相当于map[string]{interface}

Gorm

框架下载

go get -u github.com/jinzhu/gorm

Go语法相关

项目入口

与C和C++类似,整个Go项目有一个文件入口main.go,代码如下方所示

package main

import "fmt"

func main() {
	fmt.Println("hello world!")
}

编译上面的代码需要下面的编译命令:

go run main.go

上面的代码成功输出hello world!

项目初始化

Go 项目需要先进行初始化,下面是命令

go mod init

name是项目名称,一般取<person/school/corporation>/<project_name>

例如 ZerglingChen3/MyBlog

初始化就会出现下面这个文件:

module ZerglingChen3/MyBlog

go 1.17

上面是模块名,下面是Go的版本

结构体

Similar Resources

HyperKit: an easy-to-use bridge between LedFX, WLED, Bluetooth, HomeKit, and AirPlay2

HyperKit HyperKit is an easy-to-use bridge between LedFX, WLED, Bluetooth, HomeKit, and AirPlay2. HyperKit Functionality: Custom HomeKit Menu Integrat

Aug 20, 2022

A easy-to-use and lightweight Go RPC framwork

zrpc 一个简单易用的Go RPC框架 功能 负载均衡(一致性哈希,Round-Robin, 随机) 服务注册与发现 心跳功能 超时处理(调用超时,连接超时,处理超时) 支持TCP/HTTP网络协议 连接复用 同步/异步调用 支持gob/json序列化协议 简单用法 创建注册中心 l, _ :=

Oct 30, 2022

A test repo to demonstrate the current (go1.17.2) issue when trying to use retractA test repo to demonstrate the current (go1.17.2) issue when trying to use retract

test-go-mod-retract This is a test repo to demonstrate the current (go1.17.2) issue when trying to use retract in go.mod to retract a version in a non

Oct 16, 2021

A tool that facilitates building OCI images

A tool that facilitates building OCI images

Buildah - a tool that facilitates building Open Container Initiative (OCI) container images The Buildah package provides a command line tool that can

Jan 3, 2023

An experiment building a custom binary protocol for a calculator

Overview Implementation of a calculator service built on a custom protocol on top of TCP Details The server is in main.go, and the client is in client

Nov 28, 2021

Boilerplate for building a monolighic Go and React application

Boilerplate for building a monolighic Go and React application

Monolithic Go and React Application Boilerplate This repository provides a simple and monolithic service with a server written in Go and frontend with

Dec 19, 2022

A boilerplate for building Gradescope autograders for Go projects.

go-autograder A boilerplate for building Gradescope autograders for Go projects. Getting started This autograder works by running all Go tests in a st

Nov 6, 2022

This Go based project of Aadhyarupam Innovators demonstrate the code examples for building microservices, integration with cloud services (Google Cloud Firestore), application configuration management (Viper) etc.

This Go based project of Aadhyarupam Innovators demonstrate the code examples for building microservices, integration with cloud services (Google Cloud Firestore), application configuration management (Viper) etc.

Dec 22, 2022

A boilerplate/starter project for quickly building APIs using Golang with Clean Architechture

A boilerplate/starter project for quickly building APIs using Golang with Clean Architechture

A boilerplate/starter project for quickly building APIs using Golang with Clean Architechture

Mar 2, 2022
Related tags
Package buildinfo provides basic building blocks and instructions to easily add build and release information to your app.
Package buildinfo provides basic building blocks and instructions to easily add build and release information to your app.

Package buildinfo provides basic building blocks and instructions to easily add build and release information to your app. This is done by replacing variables in main during build with ldflags.

Nov 14, 2021
Example blog built with Go and the Cosmic Headless CMS 🔥
Example blog built with Go and the Cosmic Headless CMS 🔥

Go + Cosmic This repo contains an example blog starter that is built with Go, and Cosmic. See live demo hosted on Heroku Prerequisites Go (I recommend

May 8, 2022
Code for the Go pipeline blog post

Concurrent and Parallel Pipelines in Go This repository contains the code that goes along with a blog post about concurrent and parallel pipelines in

Nov 11, 2022
A static blog generator for telling tall tales

Gleeman Gleeman is a toy static blog generator that aims to be a simple way to tell tales. The term "gleeman" is taken from Robert Jordan's epic fanta

Jan 14, 2022
:sunglasses:Package captcha provides an easy to use, unopinionated API for captcha generation

Package captcha provides an easy to use, unopinionated API for captcha generation. Why another captcha generator? I want a simple and framework-indepe

Dec 28, 2022
An easy to use, extensible health check library for Go applications.

Try browsing the code on Sourcegraph! Go Health Check An easy to use, extensible health check library for Go applications. Table of Contents Example M

Dec 30, 2022
An easy-to-use Map Reduce Go parallel-computing framework inspired by 2021 6.824 lab1. It supports multiple workers on a single machine right now.

MapReduce This is an easy-to-use Map Reduce Go framework inspired by 2021 6.824 lab1. Feature Multiple workers on single machine right now. Easy to pa

Dec 5, 2022
Hrple is an easy to use tool to help you create habits
Hrple is an easy to use tool to help you create habits

Hrple is an easy to use tool to help you create habits. This is loosely inspired by the book Atomic Habits by James Clear and techniques or frameworks like Kanban and the Pomodoro Technique.

Jun 2, 2022
Eye - An easy-use lib for event-driven pattern

?? Eye Eye 是一个简单易用的事件驱动模式库。 Read me in English ?? 功能特性 敬请期待。。。 历史版本的特性请查看 HISTOR

Jan 17, 2022
A fast and easy-to-use gutenberg book downloader

Gutenberg Downloader A brief description of what this project does and who it's for Usage download books Download all english books as epubs with imag

Jan 11, 2022