Skip to content

c1982/opje

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

opje

Golang Service Locator Thingy

Usage

package main

import (
	"fmt"
	"opje"
)

type AuthService interface {
	Login(username, password string) (bool, error)
	Register(username, password string) (bool, error)
}

type authentication struct{}

func newAuthService() AuthService {
	return &authentication{}
}

func (a *authentication) Login(username, password string) (bool, error) {
	return true, nil
}

func (a *authentication) Register(username, password string) (bool, error) {
	return true, nil
}

func init() {
	locator.Register(newAuthService())
}

func main() {
	auth, err := locator.Resolve[AuthService]()
	if err != nil {
		panic("authService not registered")
	}

	loggedin, err := auth.Login("admin", "admin")
	if err != nil {
		panic("login failed")
	}

	if loggedin {
		fmt.Println("Logged in ✌️")
	}
}

Releases

No releases published

Packages

No packages published

Languages