D
D
Dmitry Dmitry2021-09-23 05:34:42
go
Dmitry Dmitry, 2021-09-23 05:34:42

How to properly import local packages?

Hello guys, I got a question about splitting the project into folders, a regular server, I want to separate the models and everything else. In general, I had a question about importing a local package.

Like I used to do and it worked.

app
- package
-- package.go
- main.go

in main just did this and everything worked... Of course there was a nuance with a recursive package call, but it's true... But it doesn't work with the new version.

package main

import (
        "./package"
)

func main() {
  package.Print("Hello world!")
}


After reading the docks a little, do I now need to push each local package as a submodule in the git? And then do all this trouble with the git? Guys, please share your experience.

Python import example
from .app.folder.file import func_name

Javascript example
import {ThingA, ThingB, ThingC} from './lib/things';

Rust example
mod include_me;

Why isn't it just as easy in Go? It's very repulsive...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Dmitry, 2021-09-23
@spaiki007

After sitting around experimenting, I answered my own question, here is a link to an example of the application structure , and yes, it’s really convenient ... the main point is to use modules and that’s all ... fall off and have to bother with something else ...

D
darst, 2021-10-02
@darst

If you write a project for yourself, then it is not necessary to call it to github. You can name your project, for example "project" when initializing (go mod init) or rename it to go.mod. Then you will need to contact "project / package name". It makes sense to link to github if you are making a package for others and will place it on third-party services, then full links will help to avoid losing packages. And as Alexander Pavlyuk wrote above, in order not to lose the used third-party packages, you need to use go mod vendor.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question