Rumah >pembangunan bahagian belakang >Golang >Mengapa Saya Mendapat 'pakej XXX tiada dalam GOROOT' Semasa Membina Projek My Go?
Isu:
Apabila cuba membina projek Go, mesej ralat "pakej XXX tiada dalam GOROOT" boleh muncul.
Penyelesaian:
Dalam versi baharu Go (siaran 1.13), pembolehubah persekitaran seperti GOPATH, GOBIN, dll., tidak lagi diperlukan. Sebaliknya:
Aliran Kerja:
Contoh Kod untuk Versi 1:
add.go:
package main func addition(x int, y int) int { return x + y }
add_test.go:
package main import "testing" func TestAdd(t *testing.T) { t.Run("adding two positive numbers", func(t *testing.T) { sum := addition(2, 2) expected := 4 if sum != expected { t.Errorf("Expected %d; but got %d", expected, sum) } }) t.Run("adding two negative numbers", func(t *testing.T) { sum := addition(-3, -4) expected := -7 if sum != expected { t.Errorf("Expected %d; but got %d", expected, sum) } }) t.Run("adding one positive and one negative integer", func(t *testing.T) { sum := addition(1, -3) expected := -2 if sum != expected { t.Errorf("Expected %d; but got %d", expected, sum) } }) }
main.go:
package main import "fmt" func main() { var num1 int = 1 var num2 int = 2 sum := addition(num1, num2) product := multiplication(num1, num2) fmt.Printf("The sum of %d and %d is %d\n", num1, num2, sum) fmt.Printf("The multiplication of %d and %d is %d\n", num1, num2, product) }
Atas ialah kandungan terperinci Mengapa Saya Mendapat 'pakej XXX tiada dalam GOROOT' Semasa Membina Projek My Go?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!