예제 #1
0
func sCheck(localdb *sqlite.DB) error {
	_, err := localdb.CreateTable("Registration", models.Registration{})
	if err != nil {
		log.Println("create registration table: ", err.Error())
	}
	return err
}
예제 #2
0
func (service *membershipService) Init(key string, namespace string) (ServiceStatus, error) {
	log.Println("membership service init: " + key + "." + namespace)
	status := ServiceStatus{}
	status.Namespace = namespace

	if namespace == "" || key == "" {
		err := errors.New("key and namespace required")
		status.Status = -1
		return status, err
	}
	service.namespace = namespace
	service.key = key

	db := sqlite.DB{}
	service.db = &db
	service.db.Namespace = fmt.Sprintf("%s.%s.membership", key, namespace)
	log.Printf("initializing with namespace: %s", service.db.Namespace)
	err := service.db.Init()

	if err != nil {
		log.Println("fatal opening database")
		status.Status = -11
		return status, err
	}
	//log.Println("sanity check for registraiton")
	err = sCheck(service.db)

	if err != nil {
		log.Println("fatal initializing database")
		status.Status = -1
		return status, err
	}

	tbl := db.Table("Registration", models.Registration{})
	service.tbl = &tbl

	status.Status = 1

	return status, err
}