type data struct {
name string //struct field
}
func hostnameScan(){ // function that we want to use as value in a struct
hostname, error := os.Hostname() //Hostname is a string
if error != nil {
panic(error)
}
fmt.Println("hostname returned from Environment : ", hostname)
fmt.Println("error : ", error)
}
func main() { // How can i still use hostname
p1 := data{
name: hostnameScan()
}
syntax error: unexpected newline, expecting comma or
package main
import (
"fmt"
"os"
)
type data struct {
name string //struct field
}
func hostnameScan() string { // function that we want to use as value in a struct
hostname, error := os.Hostname() //Hostname is a string
if error != nil {
panic(error)
}
return hostname
}
func main() { // How can i still use hostname
p1 := data{
name: hostnameScan(),
}
fmt.Printf("%#v\n", p1)
}
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.