From e28b6f056b57f1a5199f1d233cecf3d5527ad89b Mon Sep 17 00:00:00 2001 From: Nicolas Paul Date: Wed, 31 May 2023 12:32:17 +0200 Subject: Move types in their own files Signed-off-by: Nicolas Paul --- pkg/types/index.go | 47 +++++++++++++++++++++++++++++++++++ pkg/types/module.go | 25 +++++++++++++++++++ pkg/types/types.go | 71 ----------------------------------------------------- 3 files changed, 72 insertions(+), 71 deletions(-) create mode 100644 pkg/types/index.go create mode 100644 pkg/types/module.go delete mode 100644 pkg/types/types.go diff --git a/pkg/types/index.go b/pkg/types/index.go new file mode 100644 index 0000000..f58d5f2 --- /dev/null +++ b/pkg/types/index.go @@ -0,0 +1,47 @@ +package types + +import "sync" + +// Index is the global object representing the Starlark configuration. +type Index struct { + Domain string + Modules map[string]Module + // internal + lock sync.Mutex +} + +// SetDomain sets the domain of the index. +func (i *Index) SetDomain(d string) { + i.lock.Lock() + defer i.lock.Unlock() + i.Domain = d +} + +// AddModule adds a module to the index. +func (i *Index) AddModule(n string, m Module) { + i.lock.Lock() + defer i.lock.Unlock() + i.Modules[n] = m +} + +// GetModule returns a module from the index. +func (i *Index) GetModule(n string) Module { + i.lock.Lock() + defer i.lock.Unlock() + return i.Modules[n] +} + +// RemoveModule removes a module from the index. +func (i *Index) RemoveModule(n string) { + i.lock.Lock() + defer i.lock.Unlock() + delete(i.Modules, n) +} + +// CheckModule checks if a module is in the index. +func (i *Index) CheckModule(n string) bool { + i.lock.Lock() + defer i.lock.Unlock() + _, ok := i.Modules[n] + return ok +} diff --git a/pkg/types/module.go b/pkg/types/module.go new file mode 100644 index 0000000..0c4e8af --- /dev/null +++ b/pkg/types/module.go @@ -0,0 +1,25 @@ +package types + +// Vcs is an enum for version control systems supported by the standard Go +// toolchain. +// +// See https://pkg.go.dev/cmd/go#hdr-Module_configuration_for_non_public_modules +type Vcs string + +// Vcs enum. +const ( + VcsBazaar Vcs = "bzr" + VcsFossil Vcs = "fossil" + VcsGit Vcs = "git" + VcsMercurial Vcs = "hg" + VcsSubversion Vcs = "svn" +) + +// Module represents a Go module to index. +type Module struct { + Path string // module path (without domain) + Vcs Vcs // vcs system + Repo string // repository's home + Dir string // url template + File string // url template +} diff --git a/pkg/types/types.go b/pkg/types/types.go deleted file mode 100644 index 4610ad4..0000000 --- a/pkg/types/types.go +++ /dev/null @@ -1,71 +0,0 @@ -package types - -import "sync" - -// Vcs is an enum for version control systems supported by the standard Go -// toolchain. -// -// See https://pkg.go.dev/cmd/go#hdr-Module_configuration_for_non_public_modules -type Vcs string - -// Vcs enum. -const ( - VcsBazaar Vcs = "bzr" - VcsFossil Vcs = "fossil" - VcsGit Vcs = "git" - VcsMercurial Vcs = "hg" - VcsSubversion Vcs = "svn" -) - -// Module represents a Go module to index. -type Module struct { - Path string // module path (without domain) - Vcs Vcs // vcs system - Repo string // repository's home - Dir string // url template - File string // url template -} - -// Index is the global object representing the Starlark configuration. -type Index struct { - Domain string - Modules map[string]Module - // internal - lock sync.Mutex -} - -// SetDomain sets the domain of the index. -func (i *Index) SetDomain(d string) { - i.lock.Lock() - defer i.lock.Unlock() - i.Domain = d -} - -// AddModule adds a module to the index. -func (i *Index) AddModule(n string, m Module) { - i.lock.Lock() - defer i.lock.Unlock() - i.Modules[n] = m -} - -// GetModule returns a module from the index. -func (i *Index) GetModule(n string) Module { - i.lock.Lock() - defer i.lock.Unlock() - return i.Modules[n] -} - -// RemoveModule removes a module from the index. -func (i *Index) RemoveModule(n string) { - i.lock.Lock() - defer i.lock.Unlock() - delete(i.Modules, n) -} - -// CheckModule checks if a module is in the index. -func (i *Index) CheckModule(n string) bool { - i.lock.Lock() - defer i.lock.Unlock() - _, ok := i.Modules[n] - return ok -} -- cgit v1.2.3