Refactoring a Go file into multiple smaller files

Posted on

Hi,

I have a main.go file under my project’s cmd/sample directory that looks like this:

package main

import (
	...
)

type AppConfig struct {
	...
}

func main() {
	...
	someFunc()
}

func someFunc() {
	...
}

Can I split this into these files, all in the main package?

cmd/sample/main.go:

package main

import (
	...
)

func main() {
	...
	someFunc()
}

cmd/sample/app_config.go:

package main

import (
	...
)

type AppConfig struct {
	...
}

cmd/sample/some_func.go:

package main

import (
	...
)

func someFunc() {
	...
}

Also how can I access AppConfig from another package?