gotify

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2019 License: MIT Imports: 4 Imported by: 3 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

gotify

a library to generate Goish variables, fields and package names from regular words

Installation

go get -u github.com/sirkon/gotify

or

dep ensure -add github.com/sirkon/gotify

Usage

package main

import (
	"fmt"

	"github.com/sirkon/gotify"
)

func main() {
	g := gotify.New(map[string]string{
		"uid": "UID",
	})
	fmt.Println(g.Public("user_id"))
	fmt.Println(g.Private("uid_1"))
	fmt.Println(g.Private("uniqId"))
	fmt.Println(g.Package("string_sum"))
	fmt.Println(g.Goimports("string_sum"))
	fmt.Println(g.True("userID"))
	fmt.Println(g.True("1userID"))
}

will output

UserID
uid1
uniqID
stringsum
string-sum
true
false

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Gotify

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

Gotify provides "gotification" of domain specific identifier names:

underscored names translates into camel case ones.

How the translation is done:

idenitifier name is splitted into chunks and each chunk is to be lowered, samples:
abc_def -> [abc, def]
AbdDef  -> [abd, def]
userId  -> [user, id]

Then there are choice:

package name (just concat)
private identifiers (first chunk is kept lowered, the rest is treated as for public identifiers)
public identifiers:

Eeach chunk is looked up in provided dictionary (id -> ID translation is always here) and is replaced with either found translation or just with titled word and then concatenated into the string

abc_def -> AbdDef
AbdDef  -> AbdDef
userId  -> UserID

func New

func New(src map[string]string) *Gotify

New constructs Gotify object

func Pure added in v0.7.0

func Pure() *Gotify

Pure чистый преобразователь без трюков

func (*Gotify) Goimports

func (g *Gotify) Goimports(data string) string

Goimports generates directory name that can be consumed by goformat utility

func (*Gotify) Package

func (g *Gotify) Package(name string) string

Package generates acceptable package name

func (*Gotify) Private

func (g *Gotify) Private(name string) string

Private translates identifier into Go private identifier name

func (*Gotify) Public

func (g *Gotify) Public(name string) string

Public translates identifier into Go public identifier name

func (*Gotify) True

func (g *Gotify) True(name string) bool

True checks if this a goish identifier

Jump to

Keyboard shortcuts

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