ref(chart): refactor ChartMember -> Member

* Fixes some style errors in #401
pull/417/head
Michelle Noorali 9 years ago
parent 9702dffc33
commit 55525696c9

@ -356,26 +356,26 @@ func loadTar(r *tar.Reader) (*tarChart, error) {
return c, nil
}
// ChartMember is a file in a chart.
type ChartMember struct {
// Member is a file in a chart.
type Member struct {
Path string `json:"path"` // Path from the root of the chart.
Content []byte `json:"content"` // Base64 encoded content.
}
// LoadTemplates loads the members of TemplatesDir().
func (c *Chart) LoadTemplates() ([]*ChartMember, error) {
func (c *Chart) LoadTemplates() ([]*Member, error) {
dir := c.TemplatesDir()
return c.loadDirectory(dir)
}
// loadDirectory loads the members of a directory.
func (c *Chart) loadDirectory(dir string) ([]*ChartMember, error) {
func (c *Chart) loadDirectory(dir string) ([]*Member, error) {
files, err := ioutil.ReadDir(dir)
if err != nil {
return nil, err
}
members := []*ChartMember{}
members := []*Member{}
for _, file := range files {
filename := filepath.Join(dir, file.Name())
if !file.IsDir() {
@ -399,13 +399,13 @@ func (c *Chart) loadDirectory(dir string) ([]*ChartMember, error) {
}
// LoadMember loads a chart member from a given path where path is the root of the chart.
func (c *Chart) LoadMember(path string) (*ChartMember, error) {
func (c *Chart) LoadMember(path string) (*Member, error) {
filename := filepath.Join(c.loader.dir(), path)
return c.loadMember(filename)
}
// loadMember loads and base 64 encodes a file.
func (c *Chart) loadMember(filename string) (*ChartMember, error) {
func (c *Chart) loadMember(filename string) (*Member, error) {
dir := c.Dir()
if !strings.HasPrefix(filename, dir) {
err := fmt.Errorf("File %s is outside chart directory %s", filename, dir)
@ -419,7 +419,7 @@ func (c *Chart) loadMember(filename string) (*ChartMember, error) {
path := strings.TrimPrefix(filename, dir)
content := base64.StdEncoding.EncodeToString(b)
result := &ChartMember{
result := &Member{
Path: path,
Content: []byte(content),
}
@ -428,8 +428,8 @@ func (c *Chart) loadMember(filename string) (*ChartMember, error) {
}
type ChartContent struct {
Chartfile *Chartfile `json:"chartfile"`
Members []*ChartMember `json:"members"`
Chartfile *Chartfile `json:"chartfile"`
Members []*Member `json:"members"`
}
func (c *Chart) LoadContent() (*ChartContent, error) {

@ -198,7 +198,7 @@ func TestLoadTemplates(t *testing.T) {
}
}
func findMember(root, path string, members []*ChartMember) error {
func findMember(root, path string, members []*Member) error {
for _, member := range members {
if member.Path == path {
filename := filepath.Join(root, path)

Loading…
Cancel
Save