首页 > 其他分享 >golang_导包

golang_导包

时间:2023-03-14 22:55:44浏览次数:57  
标签:mymath app utilset module golang 导包 go

golang导包

导包

同一个项目下的导包

img

img

文件的目录结构

.
├── README.md
├── go.mod
├── main.go
├── mymath
│   ├── multip.go
│   └── sum.go
├── tree.txt
└── utilset
└── hello.go

3 directories, 7 files

/Users/song/codelearn/go_module-master/导包/app/go.mod

module app

go 1.20

/Users/song/codelearn/go_module-master/导包/app/main.go

package main

import (
	"app/utilset"
	"app/mymath"
	"fmt"
)

func main() {
  	utilset.PrintHello()
	sum := mymath.Sum(11,22)
	fmt.Println("sum = ",sum)
	mul := mymath.Multip(11,22)
	fmt.Println("mul = ",mul)
}

/Users/song/codelearn/go_module-master/导包/app/utilset/hello.go

package utilset

import "fmt"

func PrintHello(){
	fmt.Println("Hello, 我在 utilset 目录下的 utils 包里")
}

/Users/song/codelearn/go_module-master/导包/app/mymath/multip.go

package mymath

func Multip(a,b int)int{
	return a*b
}

/Users/song/codelearn/go_module-master/导包/app/mymath/sum.go

package mymath

func Sum(a,b int)int{
	return a+b
}

标签:mymath,app,utilset,module,golang,导包,go
From: https://www.cnblogs.com/zhuoss/p/17216787.html

相关文章