pacman

package module
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2023 License: MIT Imports: 7 Imported by: 3

README

Pacman - Yet Another Toolkit to Build Golang Application Quickly

logo

LICENSE Language

Pacman is a Golang library that abstracts the common libraries and patterns used in Golang application development. It provides a set of standard interfaces and implementations that can be used to build a Golang application quickly.

Notice: This document also has Simplified Chinese 中文版本 Edition.

Why call it Pacman?

We inspired by two things:

  1. Pacman is the package manager of Arch Linux, which is a very popular Linux distribution. We want to make it easy to use third-party packages in Go projects, just like what pacman does in Arch Linux.
  2. Pacman is also a video game character, which is very popular in the 1980s. We want to make it easy to build a Golang application quickly, just like Pacman eats all the dots in the maze.

Changelog

20220919 initial release

Design Philosophy

Golang is very stable and robust for server-side application development. But some general issues are confusing and blocking the progress of development, such as:

  1. We need many third-party libraries to build the application. We need to choose a suitable one or multiple solutions at the same time, but do not want to be too dependent on them;
  2. The upgrade and replacement of third-party dependencies will cause failures, eg. some third-party libraries do not support major version updates.
  3. We're building microservices that may require common features, so we don't need to develop them repeatedly.

Based on above the issues, we began to think about how to manage third-party libraries. Far as we are aware of the Spring Boot which famous framework from Java world managing the third-party libraries or dependencies by Bean. This is the appropriate implementation for Ioc - The injection of dependencies.

Requirements and install

This project requires golang v1.18 or higher version with new features such as general generic and so on.

How to Use It

To use this toolkit is very simple and easy. For example, we wanna including the general cache module which has implemented:

First, we import the interface from the definition of the cache module.

import "github.com/segmentfault/pacman/cache/v2"

Second, we import the implementation from the other path.

import "github.com/segmentfault/pacman/contrib/cache/v2"

Finally, we use it!

cache := v2.NewCache[int, string]()
cache.Set(1, "hello")

got, ok := cache.Get(1)
assert.Equal(t, ok, true)
assert.Equal(t, got, "hello")

The cache module should be running correctly.

Contributing

Contributions are always welcome!

See contributing.md for ways to get started.

Please adhere to this project's code of conduct.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithID

func WithID(id string) func(application *Application)

WithID application add id

func WithName

func WithName(name string) func(application *Application)

WithName application add name

func WithServer

func WithServer(servers ...server.Server) func(application *Application)

WithServer application add server

func WithSignals

func WithSignals(signals []os.Signal) func(application *Application)

WithSignals application add listen signals

func WithVersion

func WithVersion(version string) func(application *Application)

WithVersion application add version

Types

type Application

type Application struct {
	// contains filtered or unexported fields
}

Application is the main struct of the application

func NewApp

func NewApp(ops ...Option) *Application

NewApp creates a new Application

func (*Application) Run

func (app *Application) Run() error

Run application run

func (*Application) Stop

func (app *Application) Stop() error

Stop application stop

type Option

type Option func(application *Application)

Option application support option

Directories

Path Synopsis
v2
contrib
cache Module
cache/memory Module
cache/redis Module
conf/viper Module
i18n Module
log/zap Module
server/grpc Module
server/http Module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL