Git Product home page Git Product logo

go-aliaser's Introduction

aliaser

Go Reference CI codecov Go Report Card

aliaser is a Go package designed to streamline the process of generating aliases for Go packages.

In Go projects, naming conflicts between imported packages and your own code can lead to verbose and cumbersome code where you have to frequently alias imported package names.

aliaser solves this problem by automatically generating Go code that provides aliases for all the exported constants, variables, functions, and types in an external package. This allows you to seamlessly integrate and extend external packages without cluttering your code with manual aliases.

Installation

You need a working Go environment.

go get github.com/marcozac/go-aliaser

Usage

To use aliaser in your project, follow these steps:

  1. Create an Aliaser: Start by creating a new aliaser.Aliaser with the target package name and the pattern of the package you want to alias.
import "github.com/marcozac/go-aliaser"

a, err := aliaser.New(&aliaser.Config{TargetPackage: "mypkg", Pattern: "github.com/example/package"})
if err != nil {
  // ...
}
  1. Generate Aliases: With the Aliaser created, you can generate the aliases writing them to a io.Writer or to directly to a file.
if err := a.Generate(io.Discard); err != nil {
  // ...
}

if err := a.GenerateFile("mypkg/alias.go"); err != nil {
  // ...
}

CLI

In addition to the library, aliaser comes with a CLI tool to simplify generating aliases directly from the command line.

After installing aliaser CLI with go install (e.g. go install github.com/marcozac/go-aliaser/cmd/aliaser@latest) or by downloading a release (available soon), you can use the aliaser command to generate aliases for a package.

aliaser generate \
  --from "github.com/example/package" \
  --package "myalias" \
  --file "path/to/output/file.go"

Examples

For simple, but more detailed examples of how to use the aliaser library and CLI, see the examples directory.

Contributing

Contributions to aliaser are welcome! Whether it's reporting bugs, discussing improvements, or contributing code, all contributions are appreciated.

License

This project is licensed under the MIT License. See the LICENSE file for details.

go-aliaser's People

Contributors

marcozac avatar dependabot[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.