Like Prometheus, but for logs.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
loki/vendor/github.com/clipperhouse/stringish
renovate-sh-app[bot] d6147d81a1
fix(deps): update module github.com/influxdata/telegraf to v1.36.4 (main) (#19938)
2 months ago
..
.gitignore fix(deps): update module github.com/influxdata/telegraf to v1.36.4 (main) (#19938) 2 months ago
LICENSE fix(deps): update module github.com/influxdata/telegraf to v1.36.4 (main) (#19938) 2 months ago
README.md fix(deps): update module github.com/influxdata/telegraf to v1.36.4 (main) (#19938) 2 months ago
interface.go fix(deps): update module github.com/influxdata/telegraf to v1.36.4 (main) (#19938) 2 months ago

README.md

stringish

A small Go module that provides a generic type constraint for “string-like” data, and a utf8 package that works with both strings and byte slices without conversions.

type Interface interface {
	~[]byte | ~string
}

Go Reference Test Status

Install

go get github.com/clipperhouse/stringish

Examples

import (
    "github.com/clipperhouse/stringish"
    "github.com/clipperhouse/stringish/utf8"
)

s := "Hello, 世界"
r, size := utf8.DecodeRune(s)   // not DecodeRuneInString 🎉

b := []byte("Hello, 世界")
r, size = utf8.DecodeRune(b)    // same API!

func MyFoo[T stringish.Interface](s T) T {
    // pass a string or a []byte
    // iterate, slice, transform, whatever
}

Motivation

Sometimes we want APIs to accept string or []byte without having to convert between those types. That conversion usually allocates!

By implementing with stringish.Interface, we can have a single API, and single implementation for both types: one Foo instead of Foo and FooString.

We have converted the unicode/utf8 package as an example -- note the absence of*InString funcs. We might look at x/text next.

Used by

Prior discussion