To initialize Limen, you need a database connection, a GORM adapter, and a list of plugins. You can provide the Secret directly in the limen.Config struct or via the LIMEN_SECRET environment variable.
Limen provides an auth.Handler() which can be mounted to any standard Go http.ServeMux or compatible router.
package main
import (
"log"
"net/http"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"github.com/thecodearcher/limen"
gormadapter "github.com/thecodearcher/limen/adapters/gorm"
credentialpassword "github.com/thecodearcher/limen/plugins/credential-password"
)
func main() {
db, err := gorm.Open(postgres.Open("your-dsn"), &gorm.Config{})
if err != nil {
log.Fatal(err)
}
auth, err := limen.New(&limen.Config{
BaseURL: "http://localhost:8080",
Database: gormadapter.New(db),
Secret: []byte("your-32-byte-secret-key-here!!!!"),
Plugins: []limen.Plugin{
credentialpassword.New(),
},
})
if err != nil {
log.Fatal(err)
}
mux := http.NewServeMux()
mux.Handle("/api/auth/", auth.Handler())
log.Println("listening on :8080")
log.Fatal(http.ListenAndServe(":8080", mux))
}