Skip to content

Commit

Permalink
safer GetProject()
Browse files Browse the repository at this point in the history
  • Loading branch information
yzqzss committed May 25, 2024
1 parent 0c0d7f1 commit 661bb5d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"os"
"path/filepath"
)

type Meta struct {
Expand Down Expand Up @@ -58,10 +59,15 @@ func GetProjectsName() []string {
}

func GetProject(project_name string) *Project {
project_file_path := fmt.Sprintf("%s/%s/%s", PROJECTS_DIR, project_name, PROJECT_FILE)
project_data, _ := os.ReadFile(project_file_path)
// project_file_path := fmt.Sprintf("%s/%s/%s", PROJECTS_DIR, project_name, PROJECT_FILE)
project_file_path_safe, err := filepath.Abs(filepath.Join(PROJECTS_DIR, project_name, PROJECT_FILE))
if err != nil {
return nil
}
project_data, _ := os.ReadFile(project_file_path_safe)
project := Project{}
err := json.Unmarshal(project_data, &project)

err = json.Unmarshal(project_data, &project)
if err != nil {
return nil
}
Expand Down

0 comments on commit 661bb5d

Please sign in to comment.