Skip to content

alextanhongpin/go-openid

Repository files navigation

go-openid

Creating an OpenID Connect with golang. Things I've learn throughout the process.

  • how to setup enum
  • bitwise operator for conditionals

Wiring Dependencies

Using wire.

func ProvideRepository() *database.ClientKV {
	return database.NewClientKV()
}

func ProvideModel(r repository.Client, v map[string]schema.Validator) *clientModelImpl {
	return NewClientModelImpl(r, v)
}

func ProvideService(m model.Client) *clientServiceImpl {
	return NewClientServiceImpl(m)
}

var ClientMegaSet = wire.NewSet(
	ProvideRepository,
	wire.Bind(new(repository.Client), new(database.ClientKV)),
	ProvideModel,
	wire.Bind(new(model.Client), new(clientModelImpl)),
	ProvideService)

var ClientSet = wire.NewSet(
	// Creates a new pointer to the struct *ClientKV.
	database.NewClientKV,

	// Map the struct *ClientKV to the interface repository.Client to be
	// used as the next argument.
	wire.Bind(new(repository.Client), new(database.ClientKV)),

	// Accepts the previous repository.Client interface, but skip the
	// second argument. The second argument will be required as a
	// parameter, since we do not defined it here. Returns a pointer to the
	// struct *clientModelImpl.
	NewClientModelImpl,

	// Take the previous struct pointer and convert it to the interface
	// type.
	wire.Bind(new(model.Client), new(clientModelImpl)),

	// Takes the previous interface and returns a pointer to the
	// *clientServiceImpl.
	NewClientServiceImpl)

Both produces the same result:

// Code generated by Wire. DO NOT EDIT.

//go:generate wire
//+build !wireinject

package client

import (
	database "github.com/alextanhongpin/go-openid/internal/database"
	schema "github.com/alextanhongpin/go-openid/pkg/schema"
)

// Injectors from wire.go:

func NewService(arg map[string]schema.Validator) *clientServiceImpl {
	clientKV := database.NewClientKV()
	clientClientModelImpl := NewClientModelImpl(clientKV, arg)
	clientClientServiceImpl := NewClientServiceImpl(clientClientModelImpl)
	return clientClientServiceImpl
}

func NewSimplerService(arg map[string]schema.Validator) *clientServiceImpl {
	clientKV := ProvideRepository()
	clientClientModelImpl := ProvideModel(clientKV, arg)
	clientClientServiceImpl := ProvideService(clientClientModelImpl)
	return clientClientServiceImpl
}

TODOS

  • add check login multiple time (and captcha)
  • add block ip functionality

About

Creating an openid with golang

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published