“This is the 15th day of my participation in the First Challenge 2022. For details: First Challenge 2022”
Where there is life, there is learning
digression
Today is Saturday, and learn to love me, I love learning, and see who is in the sunny day was painstakingly cultivated, who is still roam in the sea of books, that’s right is me, carry out the embodiment of love and justice, lovely and charming villain, through the nuggets online, the author of a white hole white tomorrow, that’s it.
Without further ado, load up
Open source project — GO-gin-API
go-gin-api
This is a project mainly based on gin framework, including some common functions, including logging, menus, permissions, code generation functions.
main.go
Last time we finished the configuration file, today we can officially see the code
The first must be the project entry file main.go, as follows
Don’t ask me why there are wavy lines below, because I have deleted the project by hand, this is the new clone down, hurry to write just to settle
A package B package C package D package
Import contains the related packages to be imported, including built-in packages (non-flouted) and third-party packages (flouted). How about this
The scope of import is a single file and does not apply to other files in the package
We all know that import can import custom packages, but if two packages import from each other, there will be a deadlock-like situation. In this case, you can use the form import _ “name”, which only imports the init method of the package, but does not use the package, and does not show that the rest of the package is used. Other functions of the package cannot be used either.
Import also supports aliases, import.” FMT “, so that FMT can be used directly without adding FMT, such as FMT.Println can be written as Println
Import (. "FMT") fmt.println (" hello world ") // Can be omitted Println(" hello world ") import(f "FMT") Namely f.P rintln (" hello world ")Copy the code
FMT package
Probably the most common package in Go (to my knowledge), FMT contains the related functions for formatting output commonly used in Go, namely printing.
There are three common methods
func Print(a ... interface{}) (n int, err error) func Printf(format string, a ... interface{}) (n int, err error) func Println(a ... interface{}) (n int, err error)Copy the code
Printf generates a formatted string from the format argument and writes it to standard output, returning the number of bytes written and any errors encountered.
The format argument contains different placeholders, integer placeholders, floating point and complex component (real and imaginary) placeholders, string placeholders, character slice placeholders, and pointer placeholders
This is the official document placeholder part, you can take a look, there are many placeholders is very useful, such as output maximum character width, can not call the function interception, conversion to base, safe transfer and so on.
We’ll talk about it in the next one, so stay tuned
After reading, you find any mistakes, write them down below! Rub it in with my Black Tiger Fu!