Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ updates:
patterns:
- "*"

- package-ecosystem: "gomod"
directory: "/id"
schedule:
interval: "daily"
commit-message:
prefix: "[id]"
include: "scope"
allow:
- dependency-type: all
groups:
main:
patterns:
- "*"

- package-ecosystem: "gomod"
directory: "/tst"
schedule:
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/sub_id.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: id

on:
workflow_dispatch: {}

push:
branches: [ main ]

pull_request:
branches: [ main ]
paths:
- .golangci.yml
- tools/**
- .github/workflows/ci.yml
- .github/workflows/sub_id.yml
- id/**

jobs:

ci:
uses: ./.github/workflows/ci.yml
with:
mod_path: id
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
39 changes: 6 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,12 @@
https://docs.codecov.com/docs/status-badges
-->

## http

[Readme](http/README.md)    
[![ci](https://github.com/ifnotnil/x/actions/workflows/sub_http.yml/badge.svg)](https://github.com/ifnotnil/x/actions/workflows/sub_http.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/ifnotnil/x/http)](https://goreportcard.com/report/github.com/ifnotnil/x/http)
[![PkgGoDev](https://pkg.go.dev/badge/github.com/ifnotnit/x/http)](https://pkg.go.dev/github.com/ifnotnil/x/http)
[![Version](https://img.shields.io/github/v/tag/ifnotnil/x?filter=http%2F*)](https://pkg.go.dev/github.com/ifnotnil/x/http?tab=versions)
[![codecov](https://codecov.io/gh/ifnotnil/x/graph/badge.svg?token=n0t9q5Y3Sf&component=http)](https://codecov.io/gh/ifnotnil/x)

Install: `go get -u github.com/ifnotnil/x/http`
| Module | Description |
| -------- | ------- |
| `http` | [![ci](https://github.com/ifnotnil/x/actions/workflows/sub_http.yml/badge.svg)](https://github.com/ifnotnil/x/actions/workflows/sub_http.yml) [![Go Report Card](https://goreportcard.com/badge/github.com/ifnotnil/x/http)](https://goreportcard.com/report/github.com/ifnotnil/x/http) [![PkgGoDev](https://pkg.go.dev/badge/github.com/ifnotnit/x/http)](https://pkg.go.dev/github.com/ifnotnil/x/http) [![Version](https://img.shields.io/github/v/tag/ifnotnil/x?filter=http%2F*)](https://pkg.go.dev/github.com/ifnotnil/x/http?tab=versions) [![codecov](https://codecov.io/gh/ifnotnil/x/graph/badge.svg?token=n0t9q5Y3Sf&component=http)](https://codecov.io/gh/ifnotnil/x)<br>Install: `go get -u github.com/ifnotnil/x/http`<br><br>[Readme](http/README.md)<br>http middlewares and inbound/outbound loggers |
| `conf` | [![ci](https://github.com/ifnotnil/x/actions/workflows/sub_conf.yml/badge.svg)](https://github.com/ifnotnil/x/actions/workflows/sub_conf.yml) [![Go Report Card](https://goreportcard.com/badge/github.com/ifnotnil/x/conf)](https://goreportcard.com/report/github.com/ifnotnil/x/conf) [![PkgGoDev](https://pkg.go.dev/badge/github.com/ifnotnit/x/conf)](https://pkg.go.dev/github.com/ifnotnil/x/conf) [![Version](https://img.shields.io/github/v/tag/ifnotnil/x?filter=conf%2F*)](https://pkg.go.dev/github.com/ifnotnil/x/http?conf=versions) [![codecov](https://codecov.io/gh/ifnotnil/x/graph/badge.svg?token=n0t9q5Y3Sf&component=conf)](https://codecov.io/gh/ifnotnil/x)<br>Install: `go get -u github.com/ifnotnil/x/conf`<br><br>[Readme](conf/README.md)<br>A [knadh/koanf](github.com/knadh/koanf) boilerplate with some helpers |
| `tst` | [![ci](https://github.com/ifnotnil/x/actions/workflows/sub_tst.yml/badge.svg)](https://github.com/ifnotnil/x/actions/workflows/sub_tst.yml) [![Go Report Card](https://goreportcard.com/badge/github.com/ifnotnil/x/tst)](https://goreportcard.com/report/github.com/ifnotnil/x/tst) [![PkgGoDev](https://pkg.go.dev/badge/github.com/ifnotnit/x/tst)](https://pkg.go.dev/github.com/ifnotnil/x/tst) [![Version](https://img.shields.io/github/v/tag/ifnotnil/x?filter=tst%2F*)](https://pkg.go.dev/github.com/ifnotnil/x/tst?tab=versions) [![codecov](https://codecov.io/gh/ifnotnil/x/graph/badge.svg?token=n0t9q5Y3Sf&component=tst)](https://codecov.io/gh/ifnotnil/x)<br>Install: `go get -u github.com/ifnotnil/x/tst`<br><br>[Readme](tst/README.md)<br>A test helper package providing error assertion test functions. |
| `id` | [![ci](https://github.com/ifnotnil/x/actions/workflows/sub_id.yml/badge.svg)](https://github.com/ifnotnil/x/actions/workflows/sub_id.yml) [![Go Report Card](https://goreportcard.com/badge/github.com/ifnotnil/x/id)](https://goreportcard.com/report/github.com/ifnotnil/x/id) [![PkgGoDev](https://pkg.go.dev/badge/github.com/ifnotnit/x/id)](https://pkg.go.dev/github.com/ifnotnil/x/id) [![Version](https://img.shields.io/github/v/tag/ifnotnil/x?filter=id%2F*)](https://pkg.go.dev/github.com/ifnotnil/x/id?tab=versions) [![codecov](https://codecov.io/gh/ifnotnil/x/graph/badge.svg?token=n0t9q5Y3Sf&component=id)](https://codecov.io/gh/ifnotnil/x)<br>Install: `go get -u github.com/ifnotnil/x/id`<br><br>[Readme](id/README.md)<br>URL Safe base64 and base 62 wrappers of uuid for text representation. |

## conf

A [knadh/koanf](github.com/knadh/koanf) boilerplate with some helpers.

[Readme](conf/README.md) &emsp; &emsp;
[![ci](https://github.com/ifnotnil/x/actions/workflows/sub_conf.yml/badge.svg)](https://github.com/ifnotnil/x/actions/workflows/sub_conf.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/ifnotnil/x/conf)](https://goreportcard.com/report/github.com/ifnotnil/x/conf)
[![PkgGoDev](https://pkg.go.dev/badge/github.com/ifnotnit/x/conf)](https://pkg.go.dev/github.com/ifnotnil/x/conf)
[![Version](https://img.shields.io/github/v/tag/ifnotnil/x?filter=conf%2F*)](https://pkg.go.dev/github.com/ifnotnil/x/conf?tab=versions)
[![codecov](https://codecov.io/gh/ifnotnil/x/graph/badge.svg?token=n0t9q5Y3Sf&component=conf)](https://codecov.io/gh/ifnotnil/x)

Install: `go get -u github.com/ifnotnil/x/conf`

## tst

A test helper package providing error assertion test functions.

[Readme](tst/README.md) &emsp; &emsp;
[![ci](https://github.com/ifnotnil/x/actions/workflows/sub_tst.yml/badge.svg)](https://github.com/ifnotnil/x/actions/workflows/sub_tst.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/ifnotnil/x/tst)](https://goreportcard.com/report/github.com/ifnotnil/x/tst)
[![PkgGoDev](https://pkg.go.dev/badge/github.com/ifnotnit/x/tst)](https://pkg.go.dev/github.com/ifnotnil/x/tst)
[![Version](https://img.shields.io/github/v/tag/ifnotnil/x?filter=tst%2F*)](https://pkg.go.dev/github.com/ifnotnil/x/tst?tab=versions)
[![codecov](https://codecov.io/gh/ifnotnil/x/graph/badge.svg?token=n0t9q5Y3Sf&component=tst)](https://codecov.io/gh/ifnotnil/x)

Install: `go get -u github.com/ifnotnil/x/tst`
4 changes: 4 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ component_management:
name: tst
paths:
- "tst/"
- component_id: id
name: id
paths:
- "id/"

ignore:
- "http/internal/testingx" # test helpers
Expand Down
11 changes: 0 additions & 11 deletions http/encoding/encoding.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package encoding

import (
"encoding/base64"
"errors"
"net/url"
"strings"
Expand All @@ -16,16 +15,6 @@ import (
"golang.org/x/text/encoding/unicode"
)

// URLSafeBase64 returns a [base64.Encoding] based on [base64.URLEncoding] replacing the default padding character ('=') padding character to a url safe one ('~').
// In URL parameters, the following characters are considered safe and do not need encoding [rfc3986](https://www.rfc-editor.org/rfc/rfc3986.html#section-3.1):
// Alphabetic characters: A-Z, a-z
// Digits: 0-9
// Hyphen: -
// Underscore: _
// Period: .
// Tilde: ~
var URLSafeBase64 = base64.URLEncoding.WithPadding('~')

// RFC5987ExtendedNotationParameterValue decodes RFC 5987 encoded filenames expecting the extended notation
// (charset "'" [ language ] "'" value-chars)
// example: UTF-8'en'file%20name.jpg
Expand Down
23 changes: 23 additions & 0 deletions id/.mockery.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# https://vektra.github.io/mockery/v3.5/configuration/

log-level: info
formatter: goimports
force-file-write: true
require-template-schema-exists: true

all: true
recursive: false
dir: '{{.InterfaceDir}}'
filename: mocks_test.go
pkgname: '{{.SrcPackageName}}'
structname: '{{.Mock}}{{.InterfaceName}}'

# https://vektra.github.io/mockery/v3.5/template/
template: testify
template-schema: '{{.Template}}.schema.json'

packages:
github.com/ifnotnil/x/id:
config:
all: true
recursive: true
8 changes: 8 additions & 0 deletions id/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
SHELL := /usr/bin/env bash

REPO_ROOT = $(shell cd .. && pwd)

include $(REPO_ROOT)/scripts/go.mk
include $(REPO_ROOT)/tools/tools.mk
include $(REPO_ROOT)/scripts/lib.mk

10 changes: 10 additions & 0 deletions id/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# id
[![ci](https://github.com/ifnotnil/x/actions/workflows/sub_id.yml/badge.svg)](https://github.com/ifnotnil/x/actions/workflows/sub_id.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/ifnotnil/x/id)](https://goreportcard.com/report/github.com/ifnotnil/x/id)
[![PkgGoDev](https://pkg.go.dev/badge/github.com/ifnotnit/x/id)](https://pkg.go.dev/github.com/ifnotnil/x/id)
[![Version](https://img.shields.io/github/v/tag/ifnotnil/x?filter=id%2F*)](https://pkg.go.dev/github.com/ifnotnil/x/id?tab=versions)
[![codecov](https://codecov.io/gh/ifnotnil/x/graph/badge.svg?token=n0t9q5Y3Sf&component=id)](https://codecov.io/gh/ifnotnil/x)

URL Safe base64 and base 62 wrappers of uuid for text representation.

The wrappers work with generics of `~[16]byte` so both `gofrs` and `google` uuid can be wrapped.
55 changes: 55 additions & 0 deletions id/base62.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package id

import (
"fmt"
"math"
"math/big"
)

type Base62 struct{}

func (e Base62) appendEncode(dst, src []byte) []byte {
if len(src) == 0 {
return nil
}

num := big.Int{}
num.SetBytes(src)
return num.Append(dst, 62)
}

func (e Base62) encodedLen(n int) int {
return base62EncodedLen(n)
}

func (e Base62) decode(dst, src []byte) (n int, err error) {
if len(src) == 0 {
return 0, nil
}

num := big.Int{}
nn, ok := num.SetString(string(src), 62)
if !ok {
return 0, fmt.Errorf("base62 error while parsing")
}

bb := nn.Bytes()
// if len(bb) != uuidSize {
// return 0, fmt.Errorf("base62 error while parsing")
// }

return copy(dst, bb), nil
}

// lg262 : log2(62) ≈ 5.954196310386875
const lg262 = 5.954196310386875

func base62EncodedLen(n int) int {
return int(math.Ceil(float64(n) * 8 / lg262))
}

func base62DecodedLen(m int) int {
return int(math.Floor(float64(m) * lg262 / 8))
}

var _ encoding = Base62{}
93 changes: 93 additions & 0 deletions id/base64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package id

import (
"encoding/base64"
)

// In URL parameters, the following characters are considered safe and do not need encoding [rfc3986](https://www.rfc-editor.org/rfc/rfc3986.html#section-3.1):
// Alphabetic characters: A-Z, a-z
// Digits: 0-9
// Hyphen: -
// Underscore: _
// Period: .
// Tilde: ~

// stdBase64 is a [base64.Encoding] based on [base64.URLEncoding] without padding character.
// alphabet of base64: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_
var (
stdBase64 = base64.URLEncoding.WithPadding(base64.NoPadding)
stdBase64WithPadding = base64.URLEncoding.WithPadding('~')
)

type Base64 struct{}

func (b Base64) encode(dst, src []byte) {
stdBase64.Encode(dst, src)
}

func (b Base64) appendEncode(dst, src []byte) []byte {
return stdBase64.AppendEncode(dst, src)
}

func (b Base64) encodeToString(src []byte) string {
return stdBase64.EncodeToString(src)
}

func (b Base64) encodedLen(n int) int {
return stdBase64.EncodedLen(n)
}

func (b Base64) appendDecode(dst, src []byte) ([]byte, error) {
return stdBase64.AppendDecode(dst, src)
}

func (b Base64) decodeString(s string) ([]byte, error) {
return stdBase64.DecodeString(s)
}

func (b Base64) decode(dst, src []byte) (n int, err error) {
return stdBase64.Decode(dst, src)
}

func (b Base64) decodedLen(n int) int {
return stdBase64.DecodedLen(n)
}

type Base64WithPadding struct{}

func (b Base64WithPadding) encode(dst, src []byte) {
stdBase64WithPadding.Encode(dst, src)
}

func (b Base64WithPadding) appendEncode(dst, src []byte) []byte {
return stdBase64WithPadding.AppendEncode(dst, src)
}

func (b Base64WithPadding) encodeToString(src []byte) string {
return stdBase64WithPadding.EncodeToString(src)
}

func (b Base64WithPadding) encodedLen(n int) int {
return stdBase64WithPadding.EncodedLen(n)
}

func (b Base64WithPadding) appendDecode(dst, src []byte) ([]byte, error) {
return stdBase64WithPadding.AppendDecode(dst, src)
}

func (b Base64WithPadding) decodeString(s string) ([]byte, error) {
return stdBase64WithPadding.DecodeString(s)
}

func (b Base64WithPadding) decode(dst, src []byte) (n int, err error) {
return stdBase64WithPadding.Decode(dst, src)
}

func (b Base64WithPadding) decodedLen(n int) int {
return stdBase64WithPadding.DecodedLen(n)
}

var (
_ encoding = Base64{}
_ encoding = Base64WithPadding{}
)
15 changes: 15 additions & 0 deletions id/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module github.com/ifnotnil/x/id

go 1.24.0

require (
github.com/ifnotnil/x/tst v0.0.2
github.com/stretchr/testify v1.11.1
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
14 changes: 14 additions & 0 deletions id/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/ifnotnil/x/tst v0.0.2 h1:6ydceMwj3uiKFu1B+TTQJcGd1KZtDOAdyy95kTgtCe4=
github.com/ifnotnil/x/tst v0.0.2/go.mod h1:TFSDsUOkXhDw6k2+vxuypmPXhJzuQ3U+qWHFc4KiMEo=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading
Loading