Tag:golang

  • Detailed explanation of basic gin routing of golang microservice framework

    Time:2021-12-29

    catalogue summary 1. Basic routing 2. Routing parameters Get all parameters of URL path Get URL path single parameter Gets the parameter specified in the URL Gets the value of the parameter that specifies the default value summary Routing is to customize the URL address and execute the specified function. A good routing definition can […]

  • Add text watermark to GIF, PNG and JPEG pictures in golang

    Time:2021-12-27

    Add watermark example Add main file “watermark/main.go” package main import ( “fmt” “watermark/textwatermark” ) func main() { SavePath := “./kaf” str := textwatermark. Fontinfo {18, “work hard”, textwatermark. Topleft, 20, 20, 255, 255, 0, 255} arr := make([]textwatermark.FontInfo, 0) arr = append(arr, str) str2 := textwatermark. Fontinfo {size: 24, message: “work hard and raise wages”, […]

  • Introduction to the difference between slice copy and equal sign copy in golang

    Time:2021-12-24

    Conclusion: Copy replication is slower than equal sign replication. However, copy copy is value copy, and changing the value of the original slice will not affect the new slice. The equal sign copy is pointer copy. Changing the original slice or new slice will affect the other. Test replication speed: func TestArr1(t *testing.T) { var […]

  • Golang represents a detailed explanation of enumeration types

    Time:2021-12-23

    Enumeration is an important data type, which is composed of a set of key value pairs. It is usually used as a constant identifier in programming language. In the main popular programming languages, such as C and Java, there is native support. In go, we can’t find enum or other keywords directly used to declare […]

  • Empty slice case in golang

    Time:2021-12-22

    Adding elements to slice with nil value is allowed in golang package main func main() { var s []int s = append(s, 1) } Run successfully~ Supplement: detailed explanation of golang slice 1、 Use of array slices func main() { //1. Create an array slice based on an array var array [10]int = [10]int{1, 2, […]

  • Implementation code of weighted load balancing algorithm using golang

    Time:2021-12-21

    Background description As shown in the figure below, load balancing acts as a reverse proxy to forward the requester’s request to the back-end service node to realize the service request. In nginx, when the server can be configured through upstream, set weight to represent the weight of the corresponding server. If there are multiple service […]

  • Take you hand in hand into the grammatical basis analysis of go language

    Time:2021-12-20

    summary Golang is a new cross platform programming language Today, Xiaobai will take you into the world of golang hand in hand (lesson 2) Go grammar Foundation The Go program can consist of multiple tags: keyword identifier constant character string Symbol keyword The go language has 25 Keywords: keyword effect var & const Declaration of […]

  • Take you hand in hand into the constant analysis of go language

    Time:2021-12-19

    summary Golang is a new cross platform programming language Today, Xiaobai will take you into the world of golang hand in hand (lesson 3) constant A constant is a fixed value that the program will not change during execution Constants can be any basic data type Such as integer constant, floating point constant, character constant, […]

  • Operator analysis of go language

    Time:2021-12-18

    summary Golang is a new cross platform programming language Today, Xiaobai will take you into the world of golang hand in hand Go operator Operators can help us perform mathematical or logical operations in programs The built-in operators of go language are: Arithmetic operator Relational operator Logical operator Bitwise Operators Assignment Operators Arithmetic operator   […]

  • Waitgroup operation for sync package in golang

    Time:2021-12-18

    Waitgroup function of sync WaitGroup When using multithreading, you can wait until the multithreading is completed before you can end the function. There are two options channel waitgroup First use channel func add (n *int , isok chan bool){ for i :=0 ;i <1000 ; i ++ { *n = *n + 1 } isok […]

  • Golang simulates the current limiting method of token bucket for access

    Time:2021-12-17

    Using channel to simulate token bucket to limit access current func FW(max int,duration time.Duration){ //Define a channel for initialization contain := make(chan bool , max) for i := 0 ; i < max ; i ++{ Contain < – true // write channel } Go func() {// start a thread for { contain <- true […]

  • Gorang language grpc practical project

    Time:2021-12-16

      1. Introduction In previous articles, we introduced protobuf and grpc. In this article, we introduced how to use grpc to develop “distributed system”. The reason for using quotation marks here is that distributed system is a big concept. In this paper, we first introduce the development of service in distributed system using grpc. Grpc […]