forked from steger/pr3-sose2026
comments
parent
50100a3035
commit
eeb9217f9f
|
|
@ -3,9 +3,17 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
// importing the myMath package with an alias mm. This allows us to use mm instead of myMath to access the functions in the package.
|
||||||
|
// go packages are imported using their full path, which is the path to the package relative to the GOPATH or module root. .
|
||||||
mm "gitty.informatik.hs-mannheim.de/steger/pr3-code/go/03-modules/myMath"
|
mm "gitty.informatik.hs-mannheim.de/steger/pr3-code/go/03-modules/myMath"
|
||||||
//_ "gitty.informatik.hs-mannheim.de/steger/pr3-code/go/03-modules/myMath"
|
|
||||||
|
|
||||||
|
// the underscore is used to import a package solely for its side effects (i.e., the init function).
|
||||||
|
// This is useful when you want to initialize a package but do not need to access any of its exported functions or variables.
|
||||||
|
// _ "gitty.informatik.hs-mannheim.de/steger/pr3-code/go/03-modules/myMath"
|
||||||
|
|
||||||
|
// importing a third-party package from GitHub. This package provides functions for generating UUIDs (Universally Unique Identifiers).
|
||||||
|
// To use this package, you need to run go get github.com/google/uuid to download and install the package in your Go workspace.
|
||||||
|
// Alternatively, you can run go mod tidy to automatically download and install any missing dependencies based on the imports in your code.
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
//run go get github.com/google/uuid
|
//run go get github.com/google/uuid
|
||||||
//or go mod tidy => go.sum
|
//or go mod tidy => go.sum
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,18 @@ package myMath
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
|
// init is a special function that is called automatically when the package is imported. It is used to initialize the package
|
||||||
|
// and can be used to set up any necessary state or perform any necessary setup before the package is used.
|
||||||
func init() {
|
func init() {
|
||||||
fmt.Println("initializing myMath")
|
fmt.Println("initializing myMath")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// functions that start with an uppercase letter are exported and can be accessed from outside the package
|
||||||
func Add(a, b int) int {
|
func Add(a, b int) int {
|
||||||
return a + b
|
return a + b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// functions that start with a lowercase letter are not exported and cannot be accessed from outside the package
|
||||||
func greater(a, b int) bool {
|
func greater(a, b int) bool {
|
||||||
return a > b
|
return a > b
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue