General

  1. Gin: A lightweight HTTP web framework that’s great for building RESTful APIs.
  2. Echo: Another web framework for Go that’s known for its speed and ease of use.
  3. GORM: An Object-Relational Mapping (ORM) library for working with databases in a Go application.
  4. Viper: A library for managing configuration files and environment variables.
  5. Logrus: A structured logger for Go, which provides flexible logging capabilities.
  6. Gorilla Mux: A powerful HTTP router and URL matcher for building custom routing logic.
  7. GoWebSocket: A library for adding WebSocket support to your Go applications.
  8. Gorilla Web Toolkit: A collection of packages for writing web applications and microservices.
  9. Cobra: A popular library for building command-line applications in Go.
  10. Testify: A testing framework that provides helpful tools and utilities for writing unit and integration tests.
  11. Docker Client: If you work with Docker containers, the official Docker client library for Go is essential.
  12. Redis Client: Libraries like “go-redis” allow you to interact with Redis databases from your Go applications.
  13. AWS SDK for Go (AWS SDKv2): If you’re working with Amazon Web Services, this SDK is essential for interacting with AWS services.
  14. gRPC: A framework for building efficient and scalable APIs using HTTP/2 and Protocol Buffers.
  15. Prometheus: A monitoring and alerting toolkit, including a client library for instrumenting your Go applications.

The choice of libraries you should master depends on your project’s requirements. It’s essential to explore and experiment with different libraries to determine which ones best fit your needs.

Web development

  1. Gin: A high-performance web framework that’s great for building RESTful APIs and web applications.
  2. Echo: A fast and minimalist web framework with a focus on simplicity and performance.
  3. GORM: An Object-Relational Mapping (ORM) library for working with databases in a Go application.
  4. chi: A lightweight, fast, and highly customizable router and middleware package for building HTTP services.
  5. Viper: A library for managing configuration files and environment variables, which is essential for configuring web applications.
  6. Gorilla Mux: A powerful HTTP router and URL matcher for building custom routing logic.
  7. Gorilla Web Toolkit: A collection of packages for writing web applications and microservices, including sessions and websockets.
  8. Negroni: A middleware-focused library that can be used to build middleware chains for your HTTP handlers.
  9. Alice: A middleware handler for Go that makes it easy to chain middleware for your HTTP handlers.
  10. Gin-JWT: A middleware for Gin that simplifies implementing JWT (JSON Web Tokens) authentication.
  11. Gin-CORS: Middleware for handling Cross-Origin Resource Sharing (CORS) in Gin applications.
  12. Gorilla Sessions: A package for managing user sessions and cookies in Gorilla-based web applications.
  13. Pongo2: A template engine for Go, useful for rendering dynamic content in web applications.
  14. Redis Client: Libraries like “go-redis” allow you to interact with Redis databases from your Go web applications, useful for caching and session management.
  15. OAuth2: If your web app requires OAuth2 authentication, libraries like “golang.org/x/oauth2” can simplify the process.
  16. File Upload: Libraries like “github.com/urfave/negroni” can help with handling file uploads in web applications.
  17. WebSockets: Libraries like “github.com/gorilla/websocket” for implementing WebSocket functionality in your web applications.
  18. CORS Middleware: Libraries like “github.com/rs/cors” can help manage Cross-Origin Resource Sharing for your APIs.

The choice of libraries and frameworks depends on your specific project requirements. Be sure to explore these options and select the ones that best suit your needs for web development in Go.

DevOps

DevOps in Golang involves a range of tasks, including automation, infrastructure provisioning, containerization, and more. While it’s not necessary to “master” specific libraries, there are some popular third-party libraries and tools in the Go ecosystem that can be very useful for DevOps tasks:

  1. Terraform: Although not a Go library itself, it’s a popular infrastructure-as-code tool that many DevOps professionals use alongside Go. You can use the hashicorp/terraform library to interact with Terraform programmatically.
  2. Packer: Another HashiCorp tool, Packer allows you to create machine images for multiple platforms. There’s a Go library (hashicorp/packer) that you can use for automation.
  3. Docker SDK for Go: If you’re working with Docker containers, the docker/docker library provides Go bindings for Docker’s remote API. It’s a powerful tool for managing containers programmatically.
  4. Kubernetes Client-Go: For Kubernetes orchestration, kubernetes/client-go is the official Go client library for interacting with Kubernetes clusters. It’s essential for automating tasks in a Kubernetes environment.
  5. AWS SDK for Go (aws-sdk-go): If you’re using Amazon Web Services, the official Go SDK is a valuable resource for automating AWS-related tasks.
  6. GolangCI-Lint: This is a Go linter that can help you maintain code quality and adhere to best practices in your Go code. It’s not specifically for DevOps but can improve the quality of your automation code.
  7. Prometheus: While not a Go library, Prometheus is often used in DevOps for monitoring and alerting. There are Go client libraries like prometheus/client_golang that help you instrument your Go applications.
  8. Gin: If you’re building HTTP services or APIs, Gin is a lightweight web framework for Go. It can be helpful for building RESTful APIs and web services for DevOps purposes.
  9. Viper: Viper is a configuration management library in Go. It’s useful for reading and managing configuration files, which is often a part of DevOps tasks.
  10. Cobra: If you’re building command-line tools for your DevOps workflows, Cobra is a popular library for creating powerful and easy-to-use CLI applications in Go.

These are just some of the third-party libraries and tools that can be beneficial for DevOps tasks in Go. Depending on your specific use case, you may need to explore other libraries and tools that are more tailored to your needs.

GORM

struct name and table name

1
2
3
4
5
6
type User struct {} // default table name is `users`

// Set User's table name to be `profiles`
func (User) TableName() string {
  return "profiles"
}

gorm不定条件查询和分页操作

making dynamic query and pagination using gorm

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
course := models.Course{}

// The global db variable must be assigned to the local db variable. 
// If you use the global db variable directly, it will affect other queries.

db := conf.GetDb()   

page, _ := strconv.Atoi(c.Query("page"))
pageSize, _  := strconv.Atoi(c.Query("page_size"))

if partner, ok := c.Query("partner"); ok == true {
    partner_id, _ := strconv.Atoi(partner)
    db = db.Where("partner_id = ?", partner_id)
}

if title, ok := c.Query("title"); ok == true {
    db = db.Where("title = ?", title)
}

if orderBy, ok := c.Query("order_by"); ok == true {
    db = db.Order(orderBy)
}

if page > 0 && pageSize > 0 {
	db = db.Limit(pageSize).Offset((page - 1) * pageSize)
}

if err := db.Find(&course).Error; err != nil {
    fmt.Println(err.Error())
}

return course, err

Database To Structs

zerolog