Go基础-模块引入

目录结构

在main.go中,引用Common模块中的代码

先进入Common中定义模块名

cd Common
go init example.com/xxx/Common

创建文件

touch Menu.go

创建函数或者类,定义为Common包

package Common

import (
   "fmt"
   "os"
)

func MainMenu() {
   fmt.Println("--------------------------------------------")
   fmt.Println(":               1、用户登录                  :")
   fmt.Println(":               2、管理员登录                :")
   fmt.Println(":               3、退出系统                  :")
   fmt.Println("--------------------------------------------")
   var mainSelected int
   fmt.Print("请选择需要的功能:")
   fmt.Scan(&mainSelected)
   switch mainSelected {
   case 1:
      UserMenu()
   case 2:
      AdminMenu()
   case 3:
      os.Exit(0)
   default:
      fmt.Print("输入有误,请重新输入")
      MainMenu()
   }
   MainMenu()
}

返回main.go所在目录,编辑代码

cd ..
package main

import (
   "example.com/xxx/Common"
)

func main() {
   Common.MainMenu()
}

使用命令,替换本地包,参数为Common包所在目录

go mod edit -replace example.com/xxx/Common=./
go mod tidy

随后在go.mod中可以看到

module Library_System

go 1.22.0

replace example.com/xxx/Common => ./Common

require example.com/xxx/Common v0.0.0-00010101000000-000000000000

即为成功

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇