01Gin source code interpretation

brief introduction Gin source code interpretation, based on v1.5.0 Edition. Process Overview On the official document, an example of getting started is as follows: 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{ "message": "po ...

Posted by brandone on Thu, 05 Dec 2019 04:09:38 -0800

Golang realizes Caesar password

I. idea of Caesar password encryption code Basic ideas: Set plaintext and shift step size (secret key) Convert clear text to lowercase, prepare clear text byte slice and ciphertext slice Each plaintext character is rotated according to the step size of displacement and stored in the ciphertext slice Return ciphertext Import package import ...

Posted by Jorge on Wed, 04 Dec 2019 03:36:55 -0800

GO array exercise

Title Requirements: In diving competition, 8 judges score, the highest score and the lowest score are removed from the athlete's score, and the average score of the remaining 6 scores is the final score (1) please find out the judges with the highest score and the lowest score (2) find out the best and worst judges. The best judges have the sm ...

Posted by beefy23 on Tue, 03 Dec 2019 16:09:41 -0800

Mutex of learning notes in Golang

The sync package in the Go language pack provides two types of locks, mutually exclusive lock (sync.Mutex) and read-write lock (sync.RWMutex) We only talk about mutex in this blog post. Mutex is a mutually exclusive lock that can be created as a field of other structures; zero value is the unlocked state. Mutex type locks are threa ...

Posted by keithschm on Mon, 02 Dec 2019 15:31:53 -0800

Make a chat room with gorilla websocket

This demo implements: Message broadcasting Heartbeat detection Chat via command line The specific logic is in websocket.go The core here is the global variable aliveList, which is responsible for distributing messages to clients. Events are passed through channel s to reduce blocking A single link will be registered in the Livelist, and ConnL ...

Posted by coderage on Sun, 01 Dec 2019 05:49:22 -0800

beego orm many to many query

First, correct the documentation of beego rel_tableSet the name of the automatically generated m2m relation tablerel_throughIf you want to use a custom m2m relationship table in an m2m relationshipSet its name in the format of pkg.path.ModelName through thiseg: app.models.PostTagRelPostTagRel table needs to have a relationship to Post and Tag ...

Posted by iii on Sat, 30 Nov 2019 20:18:16 -0800

Elastic search, gorang client aggregation query

At present, there is a requirement for es aggregation query in the monitoring project, which needs to be implemented in go language, The requirement is to query that an IP is in a time range, and the average value of each monitoring indicator in a time unit. It's a bit awkward. Here is the query statement of es. It's obvious that the two field ...

Posted by beanwebb on Sat, 30 Nov 2019 15:30:28 -0800

Golang implements requests Library

Simple package, convenient to use, like python's requests library. Github address Github Support GET,POST,PUT,DELETE application/json,application/x-www-form-urlencoded I won't support it: multipart/form-data Use The following are common examples: GET request; POST form submission, json submission, saving files, etc. Get func getText() ...

Posted by JamesyBHOY on Fri, 29 Nov 2019 13:23:41 -0800

Go GUI controls and signals

control Control Brief Control is the encapsulation of data and methods. Control has its own properties and methods. Property refers to the characteristics of the control. Method refers to some simple and visible functions of the control. For example, the button is a control. The button is square, with a picture inside. This is the appearance pr ...

Posted by weekender on Wed, 27 Nov 2019 13:33:41 -0800

Basic knowledge of function

1. Definition of function The format of Go language function definition is as follows: func function_name( parameter list ) return_types { //Function body } Function parameter Function if you use an argument, the variable can be called a parameter of the function. Formal parameters are like local variables defined in a function body. To c ...

Posted by KingOfHeart on Wed, 27 Nov 2019 06:20:45 -0800