Skip to content
listing.go 581 B
Newer Older
Lo^2's avatar
Lo^2 committed
package importer

import (
	"encoding/json"
	"fmt"
	"os"
)

type Listing []User

type User struct {
	Uuid     string
	Fullname string
	Email    string
	Admin    bool
}

func ReadListingFile(path string) (Listing, error) {
	f, err := os.Open(path)
	if err != nil {
		return nil, fmt.Errorf("Error while opening %s: %s", path, err.Error())
	}
	defer f.Close()

	configDecoder := json.NewDecoder(f)

	var listing Listing
	err = configDecoder.Decode(&listing)
	if err != nil {
		return nil, fmt.Errorf("Error parsing listing file %s: %s", path, err.Error())
	}

	return listing, nil
}