GithubHelp home page GithubHelp logo

dchapes / fmtless Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cathalgarvey/fmtless

0.0 2.0 0.0 272 KB

A toolkit for replacing fmt's output funcs, plus fmt-free stdlib replacements

License: GNU Affero General Public License v3.0

Go 100.00%
go

fmtless's Introduction

fmtless: All the convenience of fmt without the bloat

by Cathal Garvey, ©2016, Released under the GNU AGPLv3 or later

Why Avoid fmt?

The fmt library is a super-rich way to present and parse data in your Go application. I love fmt; everyone loves fmt!

However, fmt is really big, adding a large premium to output binaries. For straight compilation to static binaries, this isn't usually a dealbreaker (cf. the success of Go overall).

However, in edge-cases, like embedding Go in storage-constrained devices, or shipping a collection of small apps in Go, or when transpiling to JS, the premium can be really costly. In my own experience, removing fmt from a GopherJS application removed 0.5Mb from the output Javascript, which can be a huge deal when shipping JS.

Most fmt imports seem to use it only for output, or for errors. So, fmtless is a toolkit for rapidly porting software using fmt for output and errors, hopefully only requiring a single-line change: instead of import "fmt", just do import "github.com/cathalgarvey/fmtless"!

fmtless also has mirrors of Go's standard libraries with fmt replaced with fmtless, to reduce binary size. Try switching over and see if it makes a difference to your application!

At present the included stdlibs in this repo are lifted directly from my local install. In the future I plan to have a script pull chosen libraries directly from the most recent tag/release of Go and converts them.

Usage

Right now, it's just replace fmt with github.com/cathalgarvey/fmtless. For stdlibs, likewise, it's just "prepend your stdlib imports with github.com/cathalgarvey/fmtless". Currently supported:

  • encoding/json (was only using stdlibs for errors)
  • encoding/xml (was only using stdlibs for errors)
  • net/url (was only using stdlibs for errors)

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.