Golang Create aPackage and Upload to Github
In Go, a package is a way to group related functions, variables, and types together, making it easier to organize and maintain code. A package can be thought of as a collection of source files that are compiled together.
The Go standard library comes with many built-in packages that provide a wide range of functionality, including network and file I/O, text and string manipulation, cryptography, and much more.
In addition to the standard library, there are also many third-party packages available that can be easily installed and used in Go projects. These packages can be found in the Go package repository at https://pkg.go.dev/.
In Go, packages can be used either from the standard library, from other packages installed in your local project, or from packages hosted on GitHub and other repositories.
Using packages from the standard library or from your local project is usually simpler and faster than using packages from GitHub, since they are already available on your machine and don’t need to be downloaded or installed separately.
However, using packages from GitHub can be useful when you need functionality that is not provided by the standard library or your local packages, or when you want to reuse code that has been developed by other people or teams.
Here are some key differences between using packages from your local project versus using packages from GitHub:
- Ease of use: Using packages from your local project is usually simpler and more straightforward than using packages from GitHub. You don’t need to worry about versioning, dependencies, or network connectivity, since everything is already available on your machine.
- Dependency management: When using packages from GitHub, you need to manage dependencies explicitly, either by using a dependency manager like Go Modules or by manually downloading and installing packages and their dependencies. This can be more complex than using local packages, especially for larger projects with many dependencies.
- Versioning: When using packages from GitHub, you need to be careful about versioning, since packages can change over time and updates may introduce breaking changes. You can use a version control system like Git or a dependency manager like Go Modules to manage versions, but this requires additional effort.
- Collaboration: Using packages from GitHub can make it easier to collaborate with other developers, since you can share code and dependencies more easily. However, this also requires good communication and versioning practices to avoid conflicts and breaking changes.
Overall, the choice between using packages from your local project versus using packages from GitHub depends on your specific needs and goals. For smaller projects or quick prototypes, using local packages may be simpler and more efficient. For larger projects or collaborations, using packages from GitHub may be more appropriate.
Create go package and upload to github
- Create new project
Example : go mod init github.com/wahyueko22/go-mod-calculator
2. Create simple function inside the project
3. Upload to github
Example : https://github.com/wahyueko22/go-mod-calculator
4. Tag the github
$ git tag v0.1.1
$ git push origin v0.1.1
5. Create small project then download the created package from github
$ go get github.com/wahyueko22/go-mod-calculator@v0.1.1
6. Use the downloaded package on code
Github : https://github.com/wahyueko22/go-mod-calculator
Source :