package main
import "fmt"
func main() {
type (
fullGram int
fullKilogram int
fullTon int
)
var (
salt fullGram = 100
apples fullKilogram = 5
truck fullTon = 10
)
fmt.Printf("salt: %d, apples: %d, truck: %d\n", salt, apples, truck)
salt = fullGram(weights.callGram(100))
fmt.Printf("Type of weights.Gram: %T\n", weights.callGram(1))
}
package weight
type (
callGram int
callKilogram int
callTon int
)
I am working on a simple code program that is supposed to call a type from another custom file.
The problem I have with it is that whenever I try to import the path /Users/inanc/go/src/github.com/inancgumus/learngo/weights
my app will instantly delete the import upon my attempt to save the file.
And because of this, I can never call the file properly.
I found the solution to my problem. Turns out it was a simple matter of how I was naming the variables in the second file. I was naming the variables how I usually do by underlining the first letter and capitalizing the second. Which works fine in the main executable file, but creates an unreadable error for Golang when you are trying to call it to your main file.
By simply renaming the variables and capitalizing the first letter of the file instead, when you call it to the second file, it seems to work without any more trouble.
Thanks to everyone who tried to help me out on the matter, because I spent a few hours trying to figure out what I was doing wrong.