Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use convenience functions to register languages and models #4

Merged
merged 1 commit into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions language/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import (
type LanguageGolang struct{}

func init() {
l := &LanguageGolang{}
Languages[l.ID()] = l
Register(&LanguageGolang{})
}

var _ Language = (*LanguageGolang)(nil)
Expand Down
14 changes: 14 additions & 0 deletions language/language.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package language

import (
pkgerrors "github.com/pkg/errors"
)

// Language defines a language to evaluate a repository.
type Language interface {
// ID returns the unique ID of this language.
Expand All @@ -14,3 +18,13 @@ type Language interface {

// Languages holds a register of all languages.
var Languages = map[string]Language{}

// Register adds a language to the common language list.
func Register(language Language) {
id := language.ID()
if _, ok := Languages[id]; ok {
panic(pkgerrors.WithMessage(pkgerrors.New("language was already registered"), id))
}

Languages[id] = language
}
14 changes: 14 additions & 0 deletions model/model.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package model

import (
pkgerrors "github.com/pkg/errors"
)

// Model defines a model that can be queried for generations.
type Model interface {
// ID returns the unique ID of this model.
Expand All @@ -11,3 +15,13 @@ type Model interface {

// Models holds a register of all models.
var Models = map[string]Model{}

// Register adds a model to the common model list.
func Register(model Model) {
id := model.ID()
if _, ok := Models[id]; ok {
panic(pkgerrors.WithMessage(pkgerrors.New("model was already registered"), id))
}

Models[id] = model
}
3 changes: 1 addition & 2 deletions model/symflower.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (
type ModelSymflower struct{}

func init() {
m := &ModelSymflower{}
Models[m.ID()] = m
Register(&ModelSymflower{})
}

var _ Model = (*ModelSymflower)(nil)
Expand Down
Loading