formatparser

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2022 License: MIT Imports: 1 Imported by: 0

README

formatparser

test Codacy Badge Version Badge License Badge Go Reference

Parse format string to text token part or key token part arrays.

Installation

go get -u github.com/ghosind/formatparser

Getting Started

package main

import (
  "log"

  "github.com/ghosind/formatparser"
)

func main() {
  format := "[%time] %message"

  parts := formatparser.Parse(format)

  for _, part := range parts {
    log.Println(part)
  }
}
$ go run app.go
&{1 [}
&{2 time}
&{1 ] }
&{2 %message}

Documentation

Index

Constants

View Source
const (
	// TypeUnknown is an unknown type token
	TypeUnknown int = iota
	// TypeText is a text string
	TypeText
	// TypeKey is a key string
	TypeKey
)

Variables

View Source
var Version = "v0.1.0"

Version is the formatparser's version.

Functions

This section is empty.

Types

type FormatPart

type FormatPart struct {
	// Type is the part type, it should be TypeText or TypeKey.
	Type int
	// Value is the string value.
	Value string
}

FormatPart is a token part.

func Parse

func Parse(format string) []*FormatPart

Parse parses a format string to formatted token parts.

Jump to

Keyboard shortcuts

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