#How do you import another Go file in main.go?

7 messages · Page 1 of 1 (latest)

gloomy owl
#

Good Day! I've read "How to import local files" thread before posting this but mine does not work and I cannot solve it on my own

- Example
---- handlers
--------- test.go
---- main.go
package handlers

import "fmt"

func message() {
  fmt.Println("Hello World")
}
package main

import (
  "Example/handlers"
)

func main() {
  handlers.message()
}
green quiver
#

the function needs to begin with a capital letter - you need the function usable outside of the package rather than only for use internally to it

plain dust
#

do you init ? i think you should go mod init first

gloomy owl
#

I did go mod init

gloomy owl
#

bro I stopped doing go because I couldn't solve this - I did not know that you had to "CAPITALIZE" the first letter to do an export - that made me feel so stupid

#

Solved: export func with a CAPTIAL first letter - damn