Initial commit: EduBox V2 platform
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type Activation struct {
|
||||
Activated bool `json:"activated"`
|
||||
StudentName string `json:"studentName,omitempty"`
|
||||
Code string `json:"code,omitempty"`
|
||||
}
|
||||
|
||||
func activationFile(dataDir string) string {
|
||||
return filepath.Join(dataDir, "activation.json")
|
||||
}
|
||||
|
||||
func loadActivation(dataDir string) (*Activation, error) {
|
||||
f := activationFile(dataDir)
|
||||
data, err := os.ReadFile(f)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var a Activation
|
||||
err = json.Unmarshal(data, &a)
|
||||
return &a, err
|
||||
}
|
||||
|
||||
func saveActivation(dataDir string, a *Activation) error {
|
||||
f := activationFile(dataDir)
|
||||
data, err := json.MarshalIndent(a, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(f, data, 0644)
|
||||
}
|
||||
Reference in New Issue
Block a user