How to organize Go code with packages? For small programs, you probably don’t need to define another package other than the special package: main. For bigger programs, you might need to define your own packages to organize your code. For people who work on the same code to create many programs, they may need to define their own libraries and import these to their own programs. In my own projects, I create a folder to keep entry-point applications of my program, then I do dependency-injection and other orchestration code there. All of the other code lives inside internal folders and not get reused by the outer packages other than the ones in my program. cmd Splitting packages into sub-directories You can split packages into subdirectories, Go stdlib uses this style. Look at for example. It’s inside package. Http things belong to network things, so, they put it under net package. However, that doesn’t mean that, package can use package’s internals, it cannot. , there’s no relationship between and package in stdlib other than the organization purposes. http package net http net Each go package is a different beast on its own net http and when you split up your packages to organize your BIG package, you may make some of the internals of your package to the outside world, and so, anyone can import them. You may not want this, so, convention prevents your packages to be imported from unwanted parties. Go provides no sub-packaging mechanism internal package I explain internal packages here in this post . And, last, new gophers who are beginning to Go, create, folders, you don’t need to do that. Just put your source files into your project root. It’s better that way. src/ like: You and other people are going to use and recall them with this name. Keep them short, simple, concise and to the point. Names should be as simple as possible http, zip, and time. in names like: . Do it like: . Different packages, but because package is inside directory, if there was another package which named also as there will be no problem, because they live in separate directories. Do not use double or more words net_http net/http http net http, . . It’s clear, isn’t? package is a package that does things related somehow with networking. If it was inside package it’d imply different meanings. Let the package path speaks for what the packages does net/http http security/http if it’s familiar to the programmers ( . For example: Instead of , stdlib uses . Use common abbrevations or to the programmers in domain of the application you’re building) formattedIO fmt like For example: Instead of a model package, define a package that does user things named as Definitely avoid ultra-generic package names api, models, common, utils, helper etc. user. . Just use lowercase letters. Do not use underscores or camel-casing ( Names can contain unicode characters however I don’t recommend using this) More on this and . And to better use packages, always read stdlib’s . here here code go get always fetches from HEAD from a git repository. However, there are some workarounds. For example: You can save a package you want manually into your program, so that you can use whatever version you want. More tips . There is no package versioning in Go. here To get all of the dependencies for the current package you’re working in by typing: go get ./… You made it here! Thanks for reading! And please support me: and ! Encourage me to write more. Follow my publication. add claps to my post I’m mostly tweeting about Go, . you can follow me on twitter: @inancgumus You will receive Go tips, tutorials and notifications about my upcoming online Go course. Click on the image to subscribe to “I’m Learning Go” email list! Thank you! Originally published at blog.learngoprogramming.com on September 26, 2017.