All Projects → mikekonan → go-types

mikekonan / go-types

Licence: MIT license
Library providing opanapi3 and Go types for store/validation and transfer of ISO-4217, ISO-3166, and other types.

Programming Languages

go
31211 projects - #10 most used programming language
javascript
184084 projects - #8 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to go-types

swagger-converter
OpenAPI/Swagger 2.0 to OpenAPI 3.0 Converter WebService
Stars: ✭ 58 (+314.29%)
Mutual labels:  openapi3
whook
Build strong and efficient REST web services.
Stars: ✭ 18 (+28.57%)
Mutual labels:  openapi3
relateurl
Create a relative URL with options to minify.
Stars: ✭ 52 (+271.43%)
Mutual labels:  url
openapi
OpenAPI 3 Specification for golang
Stars: ✭ 18 (+28.57%)
Mutual labels:  openapi3
node-url-shortener
URL Shortener in Base58 using Node.js, Express, Sequelize, Mocha and Bootstrap
Stars: ✭ 21 (+50%)
Mutual labels:  url
uri
A type to represent, query, and manipulate a Uniform Resource Identifier.
Stars: ✭ 16 (+14.29%)
Mutual labels:  url
deadlink
💀 Checks and fixes URLs in code and documentation.
Stars: ✭ 105 (+650%)
Mutual labels:  url
Omeka-plugin-CleanUrl
Omeka plugin that allows to have clean, searchable and readable URL like https://example.com/my_collection/dc:identifier instead of https://example.com/items/show/internal_code.
Stars: ✭ 13 (-7.14%)
Mutual labels:  url
golgi
A composable routing library for Haxe.
Stars: ✭ 37 (+164.29%)
Mutual labels:  url
Odyssey
A piece of software that shows a traceroute of a URL redirect path
Stars: ✭ 41 (+192.86%)
Mutual labels:  url
link text
Easy to use text widget for Flutter apps, which converts inlined urls into working, clickable links
Stars: ✭ 20 (+42.86%)
Mutual labels:  url
url
Build and parse URLs. Useful for HTTP and "routing" in single-page apps (SPAs)
Stars: ✭ 69 (+392.86%)
Mutual labels:  url
opg
Rust OpenAPI 3.0 docs generator
Stars: ✭ 30 (+114.29%)
Mutual labels:  openapi3
beacon-APIs
Collection of RESTful APIs provided by Ethereum Beacon nodes
Stars: ✭ 209 (+1392.86%)
Mutual labels:  openapi3
HibiAPI
一个实现了多种常用站点的易用化API的程序 / A program that implements easy-to-use APIs for a variety of commonly used sites.
Stars: ✭ 427 (+2950%)
Mutual labels:  openapi3
sails-hook-swagger-generator
A tool to help generate Swagger specification documentation based on OAS 3.0 for Sails APIs
Stars: ✭ 71 (+407.14%)
Mutual labels:  openapi3
openapi-generator-go
An opinionated OpenAPI v3 code generator for Go. Use this to generate API models and router scaffolding.
Stars: ✭ 42 (+200%)
Mutual labels:  openapi3
laravel-linkable
URL binding for Laravel models
Stars: ✭ 22 (+57.14%)
Mutual labels:  url
kzilla.xyz
Shorten the URL. Broaden the reach.
Stars: ✭ 34 (+142.86%)
Mutual labels:  url
oas
OpenAPI Spec builder in go
Stars: ✭ 15 (+7.14%)
Mutual labels:  openapi3

Go Report Card Build Status codecov

go-types

This library has been created with the purpose to facilitate the store, validation, and transfer of Go ISO-3166/ISO-4217/timezones/emails/URL types. There is a openapi3 spec of that type and make you able to include it into your spec. All types has own ozzo.Validate, json.Unmarshaler, Stringer and driver.Valuer implementations.

Installation

go get github.com/mikekonan/go-types/v2

Usage:

package main

import (
	"encoding/json"
	"fmt"
	"log"

	validation "github.com/go-ozzo/ozzo-validation/v4"
	"github.com/mikekonan/go-types/v2/country"
	"github.com/mikekonan/go-types/v2/country/alpha2"
	"github.com/mikekonan/go-types/v2/country/alpha3"
	"github.com/mikekonan/go-types/v2/language"
	"github.com/mikekonan/go-types/v2/country/name"
	"github.com/mikekonan/go-types/v2/currency"
	"github.com/mikekonan/go-types/v2/currency/code"
	"github.com/mikekonan/go-types/v2/phone"
	"github.com/mikekonan/go-types/v2/postal_code"
)

// 1. use in your structs
type User struct {
	Name            string                `json:"name" db:"name"`
	Country         country.Alpha2Code    `json:"country" db:"country"`
	Currency        currency.Code         `json:"currency" db:"currency"`
	Language        language.Alpha2Code   `json:"language" db:"language"`
	Phone           phone.Number          `json:"phone" db:"phone"`
	CountryDialCode phone.DialCode        `json:"dialCode" db:"dialCode"`
	PostalCode      postalcode.PostalCode `json:"postalCode" db:"postalCode"`
}

func main() {
	// 2. use in your wire
	user := User{}
	_ = json.Unmarshal([]byte(`{"name":"name", "country": "CA", "currency": "CAD", "language": "fr", "phone": "123456789", "dialCode": "1"}`), &user)

	// 3. check is set
	user.Country.IsSet()
	user.Currency.IsSet()
	user.Language.IsSet()

	// 4. validate using ozzo-validation
	if err := validation.ValidateStruct(&user, validation.Field(&user.Country), validation.Field(&user.Currency)); err != nil {
            log.Fatal(err)
	}

	// 5. lookup by alpha2, alpha3, country name
	if userCountry, ok := country.ByAlpha2Code(user.Country); ok {
            fmt.Printf("country name - '%s', alpha-2 - '%s', alpha-3 - '%s'", userCountry.Name(), userCountry.Alpha2Code(), userCountry.Alpha3Code())
	}

	// 6. lookup by 2 and 3 char codes, language name
	if userLanguage, ok := language.ByAlpha2Code(user.Language); ok {
            fmt.Printf("language name - '%s', alpha-2 - '%s', alpha-3 - '%s'", userLanguage.Name(), userLanguage.Alpha2Code(), userLanguage.Alpha3Code())
	}

	// 7. lookup by country dial code
	if phoneCountries, ok := phone.CountriesByDialCode(user.CountryDialCode); ok {
            for _, phoneCountry := range phoneCountries {
                fmt.Printf("country by dial code - '%s'", phoneCountry)
            }
	}

	// 8. lookup by country
	if dialCode, ok := phone.DialByAlpha2Code(user.Country); ok {
            fmt.Printf("'%s' dial code is '%s'", user.Country, dialCode)
        }

	// 9. lookup by currency code
	if userCurrency, ok := currency.ByCode(user.Currency); ok {
            fmt.Printf("currency name - '%s', code - '%s', number - '%s', countries - '%s', decimal places - '%d'",
                userCurrency.Currency(), userCurrency.Code(), userCurrency.Number(), userCurrency.Countries(), userCurrency.DecimalPlaces())
	}

	// 10. store in db
	fmt.Println(user.Country.Value())  //prints 'CA'
	fmt.Println(user.Currency.Value()) //prints 'CAN'
	fmt.Println(user.Language.Value()) //prints 'fr'

	// 11. use specific country constants
	fmt.Println(country.Canada.Alpha2Code())
	fmt.Println("name:", name.Canada)
	fmt.Println("alpha-2:", alpha2.CA)
	fmt.Println("alpha-3:", alpha3.CAN)

	// 12. use specific currency codes
	fmt.Println(code.CAD)
}

Links:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].