DEV Community

Sudipto Biswas
Sudipto Biswas

Posted on

How to Create and Publish a Go Package (Golang)

1.Create a new project folder

At the command line create and/or browse to a folder where you keep your projects:

  1. Add a new project folder

2.Initialize a Go project
go mod init github.com/dipto0079/rest-API-to-upload-images-Golang

3.Create the library files
You need to create some empty files to update in later steps:
README.md ,LICENSE,init.go,.....

Notice that the test file ends with underscore (_) test (_test.go).

This is how the default test tool knows that the file contains tests.

4.Code Description
The code above includes an init function. The init function in Go is a special (and optional) function that is called when the package that it is in is imported. In this case I'm just using it to log a message. But you could use it for things like initializing a random seed, etc.
**
5.Fill in the license file**
Without the license file pkg.go.dev won't display your documentation.

I use the MIT License. You can copy this text and adjust the copyright info line for yourself:

MIT License

Copyright 2022 Sudipto Biswas

Permission is hereby granted, free of charge, to any person obtaining a copy 
of this software and associated documentation files (the "Software"), to deal 
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
copies of the Software, and to permit persons to whom the Software is 
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in 
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
THE SOFTWARE.
Enter fullscreen mode Exit fullscreen mode

Top comments (0)