Clean APIs for your Go Applications. Inspired by functional options pattern.


Build Status

Awesome GoLang

Report A+

License

Releases

Read me docs

Chat



Clean APIs for your Go Applications. Inspired by functional options pattern.

Quick view

package main

import (
	"fmt"
	"github.com/kataras/go-options"
)

type appOptions struct {
	Name        string
	MaxRequests int
	DevMode     bool
	EnableLogs  bool
}

type app struct {
	options appOptions
}

func newApp(setters ...options.OptionSetter) *app {
	opts := appOptions{Name: "My App's Default Name"} // any default options here
	options.Struct(&opts, setters...)                 // convert any dynamic options to the appOptions struct, fills non-default options from the setters

	app := &app{options: opts}

	return app
}

// Name sets the appOptions.Name field
// pass an (optionall) option via static func
func Name(val string) options.OptionSetter {
	return options.Option("Name", val)
}

// Dev sets the appOptions.DevMode & appOptions.EnableLogs field
// pass an (optionall) option via static func
func Dev(val bool) options.OptionSetter {
	return options.Options{"DevMode": val, "EnableLogs": val}
}

// and so on...

func passDynamicOptions() {
	myApp := newApp(options.Options{"MaxRequests": 17, "DevMode": true})

	fmt.Printf("passDynamicOptions: %#v\n", myApp.options)
}

func passDynamicOptionsAlternative() {
	myApp := newApp(options.Option("MaxRequests", 17), options.Option("DevMode", true))

	fmt.Printf("passDynamicOptionsAlternative: %#v\n", myApp.options)
}

func passFuncsOptions() {
	myApp := newApp(Name("My name"), Dev(true))

	fmt.Printf("passFuncsOptions: %#v\n", myApp.options)
}

// go run $GOPATH/github.com/kataras/go-options/example/main.go
func main() {
	passDynamicOptions()
	passDynamicOptionsAlternative()
	passFuncsOptions()
}

Installation

The only requirement is the Go Programming Language, at least v1.7.

$ go get -u github.com/kataras/go-options

FAQ

If you'd like to discuss this package, or ask questions about it, feel free to

Versioning

Current: v0.0.1

Read more about Semantic Versioning 2.0.0

People

The author of go-options is @kataras.

Contributing

If you are interested in contributing to the go-options project, please make a PR.

License

This project is licensed under the MIT License.

License can be found here.

Owner
Gerasimos (Makis) Maropoulos
🥇 That Greek Gopher | 💨 Senior Backend Engineer at PNOĒ | 🎓My dream is to create an international IT university that will produce flawless developers!
Gerasimos (Makis) Maropoulos
Similar Resources

A golang client for the Twitch v3 API - public APIs only (for now)

go-twitch Test CLIENT_ID="my client ID" go test -v -cover Usage Example File: package main import ( "log" "os" "github.com/knspriggs/go-twi

Sep 27, 2022

Auto-generated Google APIs for Go.

Google APIs Client Library for Go Getting Started $ go get google.golang.org/api/tasks/v1 $ go get google.golang.org/api/moderator/v1 $ go get google.

Jan 8, 2023

Twilight is an unofficial Golang SDK for Twilio APIs

Twilight is an unofficial Golang SDK for Twilio APIs

Twilight is an unofficial Golang SDK for Twilio APIs. Twilight was born as a result of my inability to spell Twilio correctly. I searched for a Twillio Golang client library and couldn’t find any, I decided to build one. Halfway through building this, I realized I had spelled Twilio as Twillio when searching for a client library on Github.

Jul 2, 2021

The MinIO Admin Go Client SDK provides APIs to manage MinIO services

Golang Admin Client API Reference The MinIO Admin Golang Client SDK provides APIs to manage MinIO services. This quickstart guide will show you how to

Dec 30, 2022

lambda-go-api-proxy makes it easy to port APIs written with Go frameworks such as Gin to AWS Lambda and Amazon API Gateway.

aws-lambda-go-api-proxy makes it easy to run Golang APIs written with frameworks such as Gin with AWS Lambda and Amazon API Gateway.

Jan 6, 2023

"there" also called "GoThere" aims to be a simple Go Library to reduce redundant code for REST APIs.

there "there" also called "GoThere" aims to be a simple Go Library to reduce redundant code for REST APIs. Despite the existence of the other librarie

Dec 25, 2022

Go API Client for NASA's Open APIs

Go Client for Nasa Open APIs Description The Go Client for Nasa Open APIs is a Go Client for the following Nasa Open APIs: APOD: Astronomy Picture of

Sep 24, 2021

Fluent JavaScript API for SharePoint and Microsoft Graph REST APIs

Fluent JavaScript API for SharePoint and Microsoft Graph REST APIs

PnPjs is a fluent JavaScript API for consuming SharePoint and Microsoft Graph REST APIs in a type-safe way. You can use it with SharePoint Framework,

Dec 23, 2022

Http apis with AWS CDK for Go

Http apis with AWS CDK for Go Blog: https://harshq.medium.com/building-apps-with-aws-sdk-for-golang-api-gateway-and-lambda-b254858b1d71 Useful command

Jan 4, 2022
A simple package in Golang containing helpers for functional programming

go-functools Golang package containing functools using Go generics functools is

Nov 3, 2022
Common functional data manipulation and abstraction patterns in Golang.

Functional Patterns in Golang GOMAD (Early stage) This package is still in an early stage of development. Feel free to open a PR and contribute or jus

Jan 8, 2023
Sync your bank transactions with google sheets using Open Banking APIs

Sync your bank transactions with google sheets using Open Banking APIs

Jul 22, 2022
Sync your bank transactions with google sheets using Open Banking APIs

this is a markdown version of the copy on the site landing page: https://youneedaspreadsheet.com You need a spreadsheet ?? Get on top of your finances

Jul 22, 2022
A demonstration of the transactional outbox messaging pattern (+ Log Trailing) with Amazon DynamoDB (+ Streams) written in Go.
A demonstration of the transactional outbox messaging pattern (+ Log Trailing) with Amazon DynamoDB (+ Streams) written in Go.

Transactional Outbox Pattern in Amazon DynamoDB A demonstration of the transactional outbox messaging pattern (+ Log Trailing) with Amazon DynamoDB (+

Apr 12, 2022
Expand host pattern to host list.

expandhost Expand host pattern to host list. E.g.: Expand foo[01-03,06,10-12].[beijing,wuhan].bar.com, the result will be as follows: []string{ "f

Dec 24, 2021
This library implements the pub/sub pattern in a generic way. It uses Go's generic types to declare the type of the event.

observer This library implements the pub/sub pattern in a generic way. It uses Go's generic types to declare the type of the event. Usage go get githu

Nov 16, 2022
Package rhymen/go-whatsapp implements the WhatsApp Web API to provide a clean interface for developers

go-whatsapp Package rhymen/go-whatsapp implements the WhatsApp Web API to provide a clean interface for developers. Big thanks to all contributors of

Mar 19, 2022
Fedora-new-install - Utility scripts for a clean fedora installation

fedora-new-install Utility scripts for a clean fedora installation new-install.g

Nov 8, 2022
Go library to access geocoding and reverse geocoding APIs

GeoService in Go Code Coverage A geocoding service developed in Go's way, idiomatic and elegant, not just in golang. This product is designed to open

Dec 23, 2022