GOLANG: PACKAGE, PUBLIC AND PRIVATE

I started golang to 3 month ago. I am so new and learning something everyday. I wanna learn and commit on my blog. I have got roadmap and let’s start from easy to hard 🙂

If you will use golang , you first step must learn packages. In fact golang is very modular.

Lets start coding!

I opened a empty golang project and i created a main.go
You open a terminal and ;

go mod init blogproject

Result message:

go: creating new go.mod: module blogproject
go: to add module requirements and sums:
        go mod tidy

Now your project has a package. We open a new file in your project and call it newzone. Create new go file in newzone folder;

  • Private: Lowercase first letter.
  • Public: Uppercase first letter.
package newzone

var localCustomer string //private
var Customer string //public

Let’s try at main.go :

package main

import (
	"blogproject/newzone"
)

func main() {
	c := newzone.Customer
	//You can not access localCustomer
	//lc := newzone.localCustomer
	_ = c
}

Finally, this is my first english article.

My priority is to share some knowledge while improving english.

Sometimes I want to write introductory level and sometimes advanced level articles.

Yorum bırakın

E-posta hesabınız yayımlanmayacak.

Translate »