---
# System prepended metadata

title: Go Project Documentation

---

Go Project Documentation
===
### Go Talaria Project Documentation
#### Prerequisite

One need to install Go version gol.13.4 or above from https://golang.org/dl/ and setup GOROOT and GOPATH. [check tutorial](https://golang.org/doc/install)

#### Step to follow
1. Clone Project
```
git clone http://gitlab.alterra.id/alterra/bsa/lima-sakti/research/go-project-structure.git
```
2. Enter Project directory `cd go-project-structure`
3. Setup your environment then execute `go mod init go-project-structure` and `go mod vendor` to install vendor dependencies
4. For running the server you have to run following command in the terminal.
```
# serve at localhost:8099 and start develop
$ go run main.go

# It will start your server at the port you have mentioned in the .env file.

```
5. To run the server in a port other than the default, run following command
```
# serve at localhost:<specific port> and start develop
$ go run main.go <specific port>
```
6. To create a build for your project and upload in the server, one need to run following command
```
$ go build
```

#### What inside ?
Let’s go through each component to know all about it.
```
.
├── apihelpers
├── controllers
│   └── api
│       └── v1
├── helpers
├── middlewares
├── models
├── repositories
│   └── api
│       └── v1
├── resources
│   └── api
│       └── v1
├── routers
├── seeder
├── services
│   └── api
│       └── v1
├── storage
│   └── logs
├── templates
├── tests
│   ├── features
│   └── units
├── version
│   └── api
│       └── v1
│           └── version.json
├── main.go
├── .env
├── .gitignore
└── response.json
```
1. apihelpers
    It is a component which contains helper functions which returns API responses, HTTP status codes, default messages and other, etc.
    
2. controllers
    It is a component which contains handler functions which handles particular route need to be called when there are any API requests from the client machine.
    
3. helpers
    It is a component which contains common functions which are called helper function which is generally required in all APIs one creates.
    
4. middlewares
    It is a component which provides a convenient mechanism for filtering HTTP requests and one can add as add required middleware in this component.
    
5. models
    This is a component where database structure is created which is used while Database Migration.
    
6. repositories
    This is a component for performing database-related actions such as CRUD
    
7. resources
    Resources contain all structures other than models which can be used as responses.
    
8. Routers
    It is a component where resources define the routes for the project and are used by the controller to handle the incoming request.

9. Seeder
    It is a component which adds seeding data (dummy data) while creating a database. It is an optional component but generally used to test the model.

10. Services
    This is the main component where all the core APIs for projects resides and one writes all APIs in this section.

11. Storage
    It is a component where data is stored to which is generally termed as Files or Logs.

12. Templates
    It is a component which contains the HTML templates to be used in the project.
    
13. main.go
    project go main file
    
14. .env
    it is a file which contains environment variables.

15. .gitignore
    it is a text file that tells git which files or folders to ignore in a project.

16. response.josn
    it is a json file that records all the responses of this application



