当前位置:网站首页>[go language development] start to develop Meitu station from 0 - Lesson 5 [receive pictures and upload]
[go language development] start to develop Meitu station from 0 - Lesson 5 [receive pictures and upload]
2022-06-24 17:15:00 【User 2353021】
From the beginning of this lesson, we have entered a more difficult step . This step is the core of our service , Receive picture upload . Before writing this , Let's start with another piece of software , The name of this software is postman
[ Download address ]:Postman
Postman This is for debugging interfaces . First download postman Click the address to see the following page .
Click on Download the App Then select 64-bit Download the version of .
Double click to install Postman Once installed , If you have an account , You can click login , If not , You can click on the Create Free Account Create , That is, email, password and password confirmation .
If you don't want to create an account , You can also directly click the first face Skip and go to the app Start trial directly .
The interface is as follows .
Here we are familiar with Postman The next step is to start writing code .
package main
import (
"fmt"
"log"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
fmt.Println(" Hello world ")
r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
// Start uploading interface
r.POST("/upload", func(c *gin.Context) {
// obtain Formdata Upload file object
file, err := c.FormFile("file")
// Determine whether there is an error return
if err != nil {
// If there is a record error, it returns
log.Printf(" Error receiving file ,%v", err)
// And return the result directly
c.JSON(200, gin.H{
"status": false,
"code": -1,
"msg": " Failed to upload file ",
})
} else {
// If not, get the file name
fileName := file.Filename
// Organize directories and file names , Form a save path
savePath := "./" + fileName
// Use gin Its own storage method , Save the file in the save Directory .
c.SaveUploadedFile(file, savePath)
c.JSON(200, gin.H{
"status": true,
"code": 200,
"msg": " Successful operation ",
})
}
})
// End the interface for uploading files
r.Run(":8080")
}You can see , I am here ping This interface ( An interface is defined as an access path , We can browse in the browser as well as Postman Address accessed in .) Another interface is written below , Namely upload Interface .
In this code , You can see many lines // Code at the beginning , And there is Chinese at the back . This is it. Golang The comments in . Comments serve to explain what the code means , But it does not participate in the actual operation of the program , You can understand it as the notes of the program .
Now? , Don't talk first , Copy the code above . Then press F5 Run up . Then sacrifice the one installed in front Postman To test whether our upload function is normal
According to the settings above , Then set it to the following , Then click the blue one on the right Send
Then you will find the following success marks .
And then you were visual Studio Code The uploaded file can be seen in the file management column on the left .
So far, the uploading code is completed
[go Language development ] from 0 Start to develop Meitu station —— The fourth lesson
[go Language development ] from 0 Start to develop Meitu station —— Lesson 6
No reprint without permission :RffanLAB|Rffan laboratory » [go Language development ] from 0 Start to develop Meitu station —— Lesson Five [ Receive picture upload ]
边栏推荐
- Go path customized project path package dependency
- Classic examples of C language 100
- Release! Tencent IOA and Tencent sky screen were selected into the first batch of certified products of domestic digital trusted services
- Elastic searchable snapshot function (frozen Tier 3)
- A comprehensive understanding of fiber to home FTTH and optical splitter
- 5g brings opportunities and challenges. Are you ready to defend against DDoS?
- How to compile and debug go runtime source code
- "Gambler" bubble Matt turns around
- Several cloud products of Tencent cloud have passed IPv6 enabled cloud logo certification
- zblog系统实现前台调用当天发布文章数量的教程
猜你喜欢

Daily algorithm & interview questions, 28 days of special training in large factories - the 15th day (string)

MySQL learning -- table structure of SQL test questions

Why do you develop middleware when you are young? "You can choose your own way"
![[leetcode108] convert an ordered array into a binary search tree (medium order traversal)](/img/e1/0fac59a531040d74fd7531e2840eb5.jpg)
[leetcode108] convert an ordered array into a binary search tree (medium order traversal)
随机推荐
IBM:以现代化架构支撑AI与多云时代的企业数字化重塑
Introduction to koa (IV) koa operation database
主链系统发展解析
Future banks need to think about today's structure with tomorrow's thinking
Activeindex selection and redirection in the menu bar on the right of easycvs
[web] what happens after entering the URL from the address bar?
Bypass kernel function pointer integrity check
A tutorial on how the zblog system obtains user related information based on user ID
Let ups "Impressionist users" re understand reliability
FPGA systematic learning notes serialization_ Day9 [serial port printing of PS terminal of Xilinx zynq7000 series]
Install Clickhouse client code 210 connection referred (localhost:9000)
API documents are simple and beautiful. It only needs three steps to open
Introduction to visual studio shortcut keys and advanced gameplay
Low education without food? As an old Android rookie in the past six years, I was the most difficult one
未来银行需要用明天的思维,来思考今天架构
FPGA project development: experience sharing of lmk04821 chip project development based on jesd204b (I)
In those years, I insisted on learning the motivation of programming
Research on clock synchronization performance monitoring system based on 1588v2 Technology
AFG EDI requirements details
Learn typescript with VAM (phase 1)