I need to know why this code will not compile, the go compiler keeps telling me im using an invalid-utf encoding, but I don't understand exactly where this is occurring. The error I'm receiving.
$ go build Example#2.go
command-line-arguments
.\Example#2.go:32:15: invalid UTF-8 encoding
Any help at all on this would be most appreciated. I know its a simple program but its to demonstrate the language to my programming languages class and this is just supposed to be a simple example showing how method names have to be linked to structs and how interfaces work. Like I said this works on go playground
but not with the actual compiler.
package main
import (
"fmt"
)
type Person struct {
Name string
Address Address
}
type Address struct {
Number string
Street string
City string
State string
Zip string
}
type Citizen struct {
Country string
Person
}
type speak interface {
Talk()
}
func (p *Person) Talk() {
fmt.Println("Hi, my name is", p.Name)
}
func (p *Person) Location() {
fmt.Printf("I’m at %v %v %v %v %v
", p.Address.Number,
p.Address.Street, p.Address.City, p.Address.State, p.Address.Zip)
}
func (c *Citizen) Nationality() {
fmt.Println(c.Name, "is a citizen of", c.Country)
}
func (c *Citizen) Talk() {
fmt.Println("this is the citizen talk method")
}
func Converse(s speak) {
s.Talk()
}
func main() {
p := Person{
Name: "Jim",
Address: Address{
Number: "1",
Street: "College Avenue",
City: "exampleland",
State: "StateLand",
Zip: "8675309",
},
}
c := Citizen{}
c.Name = "John"
c.Country = "Somewhereland"
c.Person.Address.Number = "1337"
c.Person.Address.Street = "Haxor Lane"
c.Person.Address.City = "Lazy"
c.Person.Address.State = "Foo"
c.Person.Address.Zip = "192.168.1.1"
p.Talk()
p.Location()
///////////////
fmt.Println("")
///////////////
c.Person.Talk()
c.Talk()
///////////////
fmt.Println("")
///////////////
c.Nationality()
c.Location()
///////////////
fmt.Println("")
Converse(&p)
Converse(&c)
}
Turns out that this was caused by the apostrophe in "I'm" //>> fmt.Printf("I’m at %v %v %v %v %v ", p.Address.Number,p.Address.Street, p.Address.City, p.Address.State, p.Address.Zip)