日常生活的交流与学习

首页 新随笔 联系 管理

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
}
posted on 2023-03-14 22:49  lazycookie  阅读(12)  评论(0编辑  收藏  举报