This is the 22nd day of my participation in Gwen Challenge

If ❤️ my article is helpful, welcome to comment, follow, like. This is the biggest encouragement for me to continue my technical creation. More previous posts on my personal blog

Many programmers joke that they are CV engineers, but now there is a way to help you without CV. This method, called “fishing for fish”, actually “increases productivity”, will help you to “new peak of life”.

Create your own Go Module

preface

Since go 1.13, the official release of the package management tool Go Module, since the online introduction:

  • How to use the Go Module
  • What useful Go Modules are there
  • Introduce a Go Module each day

There are lots of articles like this, but few mention how to create your own Go Module.

Then some old pedant will come out and say it is not good to repeat the wheel;

But Chopin can’t play out brother’s sadness. While there are lessons to be learned from lofty solutions, different business scenarios have their own unique requirements. Lofty solutions are not always easy to use, much less comfortable.

Compared with theYour own efficiency,comfortableIs concerned. Which is the wheel?

Therefore, it is better to teach a man to fish than to teach him to fish. In this article, we will tell you how to create your own Go Module.

Go to a gay website and create Git

https://github.com/new(ifGithub access is slowIf so, use domesticgiteeNo problemDaily development and maintenanceModule Version Release

Git Clone [email protected]:coderdao/my_go_mod.git

So let me just write an original version

Go to project my_go_module and add first_kiss.go:

forfirst_kiss.goAdd two methods and associated annotations

Run go mod init to generate the go.mod file

This step is mainly used when you need to update your own module version or rely on a third module in the future:

MINGW64 /d/Dev/workplace/golang/my_go_mod (main)
$ go mod init github.com/coderdao/my_go_mod
go: creating new go.mod: module github.com/coderdao/my_go_mod
go: to add module requirements and sums:
        go mod tidy
Copy the code

Push the project to pkg.go.dev

[pkg.go.dev](https://pkg.go.dev)The site isGolang officialDeveloped a resource website that provides retrieval functions for Golang third-party packages

When we successfully push, we can search again in pkg.go.dev (this may take a while, about 10 minutes to half an hour) and see the results

Go to another project and pull my_go_mod test

If the first pull does not respond, wait a few minutes for synchronization. Pull again until it prints out a message

Then write the test file, test