A comparative analysis of golang socket and Linux socket

After posix standard was introduced, socket has been well supported on all major OS platforms. Golang is a cross platform programming language with runtime. The socket API provided to developers in Go is based on the native socket interface of the operating system. But the behavior of socket interface in golang is different from that of native ...

Posted by art15 on Mon, 09 Dec 2019 18:41:31 -0800

go language to realize chat room

go language to realize chat room Chat room is divided into server and client. The first part is the server code, the second part is the client code. I. server code //chatroom server package main import ( "fmt" "net" ) //Define the function checkError for error handling func checkError(err error) { if err != nil { panic ...

Posted by printf on Sat, 07 Dec 2019 12:30:54 -0800

Efficient string splicing in Go language

+ number splicing This kind of splicing is the simplest and easiest for us to use, because it is not limited to programming languages, such as Go language, Java, and they are + operators, which are calculated at runtime. var s string s+="Nickname?"+":"+"Zhiqiang 1224"+"\n" s+="Contact information QQ"+":"+"354662600"+"\n" fmt.Println(s) fmt spl ...

Posted by dan90joe on Sat, 07 Dec 2019 11:18:54 -0800

Realize the connection between Golang and Erlang (Port)

title: realize the connection between Golang and Erlang (Port) categories: Golang In Erlang, there are many ways to interact with other languages. The common ways are Interaction using TCP protocol Using Port Using ERL? Interface to realize CNode NIF The latter several kinds of difficulties are all there, but also use a more complex C/C + +, ...

Posted by tha_mink on Fri, 06 Dec 2019 14:36:07 -0800

02Gin Source Interpretation

brief introduction HttpRouter implementation data structure Add Route addRoute insertChild get data summary brief introduction Gin source interpretation, based on v1.5.0 Edition. HttpRouter implementation Adding routes is mainly done by addRoute: func (engine *Engine) addRoute(method, path string, handlers HandlersChain) { assert1(pa ...

Posted by mabwi on Fri, 06 Dec 2019 14:08:46 -0800

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