diff options
Diffstat (limited to 'pkg/types')
| -rw-r--r-- | pkg/types/index.go | 6 | ||||
| -rw-r--r-- | pkg/types/module.go | 23 | 
2 files changed, 20 insertions, 9 deletions
diff --git a/pkg/types/index.go b/pkg/types/index.go index 623555c..ebb6f52 100644 --- a/pkg/types/index.go +++ b/pkg/types/index.go @@ -10,7 +10,7 @@ import (  // Index is the global object representing the Starlark configuration.  type Index struct {  	Domain  string -	Modules map[string]Module +	Modules map[string]*Module  	// internal  	lock sync.Mutex  } @@ -23,14 +23,14 @@ func (i *Index) SetDomain(d string) {  }  // AddModule adds a module to the index. -func (i *Index) AddModule(n string, m Module) { +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 { +func (i *Index) GetModule(n string) *Module {  	i.lock.Lock()  	defer i.lock.Unlock()  	return i.Modules[n] diff --git a/pkg/types/module.go b/pkg/types/module.go index e0ec5ea..ad3208f 100644 --- a/pkg/types/module.go +++ b/pkg/types/module.go @@ -6,6 +6,7 @@ import (  	"os"  	"path"  	"strings" +	"sync"  )  // Vcs is an enum for version control systems supported by the standard Go @@ -30,21 +31,31 @@ type Module struct {  	Repo string // repository's home  	Dir  string // url template  	File string // url template + +	// internal +	mu sync.Mutex  }  // GenerateFile generates the index file.  func (m *Module) GenerateFile(out string, domain string) error { +	m.mu.Lock() +	p := m.Path +	v := m.Vcs +	r := m.Repo +	d := m.Dir +	f := m.File +	m.mu.Unlock() -	f := path.Join(out, m.Path+".html") +	outf := path.Join(out, p+".html")  	// Create the file. -	if strings.Contains(m.Path, "/") { -		if err := os.MkdirAll(path.Dir(f), 0755); err != nil { +	if strings.Contains(p, "/") { +		if err := os.MkdirAll(path.Dir(outf), 0755); err != nil {  			return err  		}  	} -	fd, err := os.Create(f) +	fd, err := os.Create(outf)  	if err != nil {  		return err  	} @@ -57,8 +68,8 @@ func (m *Module) GenerateFile(out string, domain string) error {  	// Execute the template and write the output to the file.  	if err := templates.ExecModule(fd, -		fmt.Sprintf("%s/%s", domain, m.Path), string(m.Vcs), -		m.Repo, m.Dir, m.File); err != nil { +		fmt.Sprintf("%s/%s", domain, p), string(v), r, +		d, f); err != nil {  		return err  	}  | 
