README

go-formatter

Go Report Card Documentation license GitHub version GitHub issues

This is a Golang library which contains formatting related functions.

Expand ▾ Collapse ▴

Documentation

Index

Constants

View Source
const (
	// BYTE defines a filesize of 1 byte
	BYTE = 1.0

	// KILOBYTE defines a filesize of 1 kilobyte
	KILOBYTE = 1000 * BYTE

	// MEGABYTE defines a filesize of 1 megabyte
	MEGABYTE = 1000 * KILOBYTE

	// GIGABYTE defines a filesize of 1 gigabyte
	GIGABYTE = 1000 * MEGABYTE

	// TERABYTE defines a filesize of 1 terabyte
	TERABYTE = 1000 * GIGABYTE
)
View Source
const DefaultFormatSQLAPIURL = "https://sqlformat.org/api/v1/format"

    DefaultFormatSQLAPIURL is the URL used to do the formatting

    Variables

    View Source
    var DefaultTimeout = 5 * time.Second

      DefaultTimeout is the default tiemout for the HTTP client

      View Source
      var (
      	// ErrSQLInvalidStatement is the error returned when the SQL statement is invalid
      	ErrSQLInvalidStatement = errors.New("Invalid SQL statement")
      )
      View Source
      var FormatSQLAPIURL = DefaultFormatSQLAPIURL

        FormatSQLAPIURL is the URL used to do the formatting

        Functions

        func Color

        func Color(value string) string

          Color formats a color by:

          - Stripping the # prefix - Changing all components to uppercase - Making sure it contains 6 digits

          func DurationInMilliseconds

          func DurationInMilliseconds(d time.Duration) string

            DurationInMilliseconds formats a duration as milliseconds (including the suffix "ms")

            func Elapsed

            func Elapsed(duration int64, empty string) string

              Elapsed forrmats a duration in HH:MM:SS showing empty if the duration is less or equal than 0

              func FileSize

              func FileSize(bytes int64) string

                FileSize formats the filesize as a string with a precision of 2 decimals

                func FileSizeWithPrecision

                func FileSizeWithPrecision(bytes int64, precision int64) string

                  FileSizeWithPrecision formats the filesize as a string with a custom precision

                  func FloatWithPrecision

                  func FloatWithPrecision(value float64, precision int64) string

                    FloatWithPrecision formats a float with a custom precision

                    func IntWithSeparators

                    func IntWithSeparators(number int64) string

                      IntWithSeparators formats an integer with separators using the language Dutch

                      func JSONBytes

                      func JSONBytes(data []byte) (string, error)

                        JSONBytes pretty prints a slice of JSON bytes

                        func JSONString

                        func JSONString(data string) (string, error)

                          JSONString pretty prints a JSON string

                          func SQL

                          func SQL(sql string) (string, error)

                            SQL formats an SQL query

                            func UnixTimestamp

                            func UnixTimestamp(sec int64, layout string) string

                              UnixTimestamp formats a unix timestamp with the given layout

                              func XML

                              func XML(xmlString string) (string, error)

                                XML formats an XML string

                                Types

                                This section is empty.