Home>Article>Backend Development> Share ten excellent Go libraries

Share ten excellent Go libraries

Guanhui
Guanhui forward
2020-06-16 17:46:30 4193browse

Share ten excellent Go libraries

1. Golang-Set

Go has arrays, slices, and maps, but it does not have sets. You can use a boolean map to simulate a collection, but it's better to have an actual data type with the correct operations and semantics.

This is the address of golang-set

2. Color

Let us continue the introduction of color. When writing command programs, it is very useful to use color to highlight important messages and distinguish errors, successes, and warnings. The

color package provides a simple way to add some color to your program (see what I did?). It uses ANSII escape codes and supports Windows too!

4. Gen

The gen tool generates code for you - specifically type-aware code, which attempts to make up for the lack of templates or generics in Go

You can annotate your type with a special annotation and gen will generate the source files included in your project.

5. Gorm

Go is known for its minimalist style. Database programming is no exception. Most popular DB libraries for Go are very low-level. Gorm introduces object-relational mapping into the following features:

  • Association (Has One, Has Many, Belongs To, Many To Many, Polymorphism)

  • Callback (Before/After Create/Save/Update/Delete/Find)

  • Preloading (preloading)

  • Transaction

  • Composite Primary Key

  • SQL Builder

  • Automigration

  • Log

  • Extensible, write plug-ins based on GORM callbacks

But this does not cover everything.

If you have developed in Python before, please don't count on SQLAlchemy.

For more advanced usage, you need to look at the bottom layer.

6. Goose

One of the most important tasks when working with a relational database is managing the schema.

In some companies, modifying the database schema is considered a "terrible" change. The goose package helps you change the schema and even perform data migration if needed. You cangoose upandgoose downat will. But keep an eye on your data to make sure it's not lost or damaged.

Goose works by versioning schemas and using migration files corresponding to each schema. Migration files can use SQL commands or Go commands. Here is an example of a SQL migration file that adds a new table:

8. Ginkgo

Ginkgo is a BDD (Behavior Driven Development) testing framework. It lets you write tests using an English-like syntax and lets less technical people examine the tests (and output) and verify that they meet business requirements.

Some developers also like this style of test specification. It integrates with Go's built-in testing package and is often used in conjunction with Gomega.

9. Etcd

Etcd is a reliable distributed key-value store. The server is implemented in Go, and Go clients interact with it via gRPC.

It focuses on:

  • Simplicity: Well-defined, user-facing API (gRPC).

  • Security: Automatic TLS with optional client certificate authentication.

  • Fast: Benchmark 10,000 writes/sec.

  • Reliable: Use Raft for reasonable allocation.

10. NSQ

NSQ is a good distributed queue. I've successfully used it as a major component of a large distributed system. Here are some of its features:

  • Supports distributed topology and no SPOF.

  • Horizontally scalable (no agents, more nodes can be added to the cluster seamlessly).

  • Low latency push based messaging (performance).

  • Combined load balancing and multicast message routing methods.

  • Have Excel in both streaming (high throughput) and work-oriented (low throughput) workloads.

  • Primarily in memory (messages that exceed the high water mark are transparently retained on disk).

  • Runtime discovery service (nsqlookupd) for consumers to find producers.

  • Transport Layer Security (TLS).

  • Data format detection.

  • Few dependencies (easy to deploy) and sensible, bounded default configuration.

  • The simple TCP protocol supports any language in the client library.

  • HTTP interface for statistics, management operations and producers (no need to publish client libraries).

  • Integrate with statsd to achieve real-time detection.

  • Robust cluster management interface (nsqadmin).

Recommended tutorial: "Go Tutorial"

The above is the detailed content of Share ten excellent Go libraries. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete