Git Product home page Git Product logo

go-modules's Introduction

Go Modules

go-say-hello repository: https://github.com/anggidast/go-say-hello

Go Modules is library or dependency management

Create a Module

To create a new module use command:

go mod init module-name

Release a Module

Go has great integration with Git, to release a module we only need to create Git Tag.

Create First Module

On this lesson, before create a new module we need to create a GitHub repository to store our released module

The module name is repository link

To create a new module use command:

go mod init github.com/anggidast/go-say-hello

After create a new module, Go will automatically create a new file: go.mod

Create a new file as a module,

sayHello.go

package go_say_hello

func SayHello() string { // Capitalize to set function as public
	return "Hello"
}

After create a module file, push it to GitHub

To release module version, create Git tag on created module

git tag v1.0.0
git push origin v1.0.0

The module will have releases tag

1

go-say-hello repository: https://github.com/anggidast/go-say-hello

Add Dependency

We can add our released module to another module as dependency/library

go get module-name

Go will automatically download the dependency and add it to new module

Init new module and create a new main.go file as new module

add the dependecy with command above

2

after add dependecy, go mod file will listed the added dependency

3

Import dependency:

package main

import (
	"fmt"

	go_say_hello "github.com/anggidast/go-say-hello"
)

func main() {
	fmt.Println(go_say_hello.SayHello())
}

Upgrade Module

To upgrade module, add new Git tag to released module, and push it to GitHub

Change the version every update make

Upgrade Dependency

Manually upgrade:

  • Change dependency version at go.mod

  • Use command go get to download new version

go-modules's People

Contributors

anggidast avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.