GO learning - 004 Import and Init


GO learning - 004 Import and Init

5-init$ tree
.
├── lib1
│   └── lib1.go
├── lib2
│   └── lib2.go
└── main.go

2 directories, 3 files

lib1

package lib1

import "fmt"

func Lib1Test() {
	fmt.Println("Lib1Tese")
}

func init() {
	fmt.Println("lib1 function")
}

lib2

package lib2

import "fmt"

func Lib2Test() {
	fmt.Println("Lib2Tese")
}

func init() {
	fmt.Println("lib2 function")
}

main

package main

import (
	"mymodule/src/GolangStudy/5-init/lib1"
	"mymodule/src/GolangStudy/5-init/lib2"
)

func main() {
	lib1.Lib1Test()
	lib2.Lib2Test()
}
lib1 function
lib2 function
Lib1Tese
Lib2Tese

image-20230914142344859


Author: Liang Junyi
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint policy. If reproduced, please indicate source Liang Junyi !
  TOC