DEV Community

karoon sillapapan
karoon sillapapan

Posted on

Golang Project Level 0

Overview

This repository contains a Golang project that [briefly describe what your project does].

Prerequisites

Before you begin, ensure you have the following installed:

  • Go (version 1.16 or later recommended)
  • Git

Project Setup

Creating a New Golang Project

  1. Initialize a new Go module
   mkdir my-golang-project
   cd my-golang-project
   go mod init github.com/yourusername/my-golang-project
Enter fullscreen mode Exit fullscreen mode
  1. Create basic project structure
   mkdir -p cmd/app
   mkdir -p internal/pkg
   mkdir -p api
   touch cmd/app/main.go
Enter fullscreen mode Exit fullscreen mode
  1. Add a simple Hello World program In cmd/app/main.go:
   package main

   import "fmt"

   func main() {
       fmt.Println("Hello, Golang!")
   }
Enter fullscreen mode Exit fullscreen mode
  1. Test your application
   go run cmd/app/main.go
Enter fullscreen mode Exit fullscreen mode

Git Setup and Push

  1. Initialize Git repository
   git init
Enter fullscreen mode Exit fullscreen mode
  1. Create a .gitignore file
   touch .gitignore
Enter fullscreen mode Exit fullscreen mode
  1. Add common Go entries to .gitignore In .gitignore:
   # Binaries for programs and plugins
   *.exe
   *.exe~
   *.dll
   *.so
   *.dylib

   # Test binary, built with `go test -c`
   *.test

   # Output of the go coverage tool
   *.out

   # Dependency directories
   vendor/

   # Go workspace file
   go.work

   # IDE directories
   .idea/
   .vscode/
Enter fullscreen mode Exit fullscreen mode
  1. Create initial commit
   git add .
   git commit -m "Initial commit"
Enter fullscreen mode Exit fullscreen mode
  1. Create a repository on GitHub/GitLab/BitBucket

    • Go to GitHub/GitLab/BitBucket and create a new repository
    • Do not initialize with README, .gitignore, or license
  2. Link local repository to remote and push

   git remote add origin https://github.com/yourusername/my-golang-project.git
   git branch -M main
   git push -u origin main
Enter fullscreen mode Exit fullscreen mode

Project Structure

my-golang-project/
├── api/                  # API definitions (protobuf, OpenAPI specs)
├── cmd/                  # Main applications
│   └── app/              # The main application
│       └── main.go       # Entry point for the application
├── internal/             # Private code
│   └── pkg/              # Private packages
├── pkg/                  # Public packages
├── go.mod                # Go module definition
├── go.sum                # Go module checksums
└── README.md             # This file
Enter fullscreen mode Exit fullscreen mode

Development Workflow

  1. Adding dependencies
   go get github.com/example/package
Enter fullscreen mode Exit fullscreen mode
  1. Building the application
   go build -o bin/app cmd/app/main.go
Enter fullscreen mode Exit fullscreen mode
  1. Running tests
   go test ./...
Enter fullscreen mode Exit fullscreen mode
  1. Making changes and pushing to Git
   git add .
   git commit -m "Description of changes"
   git push
Enter fullscreen mode Exit fullscreen mode

Best Practices

  • Use go fmt to format your code before committing
  • Run go vet to catch potential issues
  • Consider using golangci-lint for comprehensive linting
  • Follow the Uber Go Style Guide for consistent code style

License

[Choose an appropriate license for your project]

Contributing

[Instructions for contributors]

Top comments (0)