Skip to content

torfjor/smartone

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tidomat smartONE handlers

Exposes a set of http.HandlerFuncs for decoding requests and encoding responses to Tidomat smartONE.

OnCodeHandler

Calls the given OnCodeFunc with the decoded request and expects (OnCodeResponse, error) in return.

Example

cmd/entry/main.go

package main

import (
	"context"
	"log"
	"net/http"

	"github.com/torfjor/smartone"
)

type AccessController interface {
	Valid(ctx context.Context, code string) (bool, error)
}

type accessController struct {}

func (a *accessController) Valid(ctx context.Context, code string) (bool, error) {
	return true, nil
}

func main() {
	if err := run(&accessController{}); err != nil {
		log.Fatal(err)
	}
}

func run(ac AccessController) error {
	http.ListenAndServe(":8080", smartone.OnCodeHandler(func(ctx context.Context, r smartone.OnCodeRequest) (smartone.OnCodeResponse, error) {
		valid, err := ac.Valid(ctx, r.Code)
		if err != nil {
			return smartone.OnCodeResponse{}, err
		}
		return smartone.OnCodeResponse{
			Result: valid,
		}, nil
	}))

	return nil
}

OnCardHandler

Not implemented yet.

About

Go http.HandlerFuncs for the Tidomat smartOne

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages