Skip to content

Commit

Permalink
Add app map
Browse files Browse the repository at this point in the history
  • Loading branch information
nomeguy committed Oct 6, 2023
1 parent fc17cbc commit 79d5ea1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions conf/app.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ isDemoMode = false
appDir = "C:/github_repos"
dbPass = ""
language = "en"
appMap =
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/beego/beego/plugins/cors"
"github.com/casbin/caswaf/object"
"github.com/casbin/caswaf/routers"
"github.com/casbin/caswaf/run"
"github.com/casbin/caswaf/service"
)

Expand All @@ -27,6 +28,7 @@ func main() {
object.InitAdapter()
object.CreateTables()
object.InitSiteMap()
run.InitAppMap()
object.StartMonitorSitesLoop()

beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
Expand Down
30 changes: 30 additions & 0 deletions run/util_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package run

import (
"encoding/json"
"fmt"
"os/user"
"path/filepath"
Expand All @@ -24,6 +25,7 @@ import (
)

var username string
var appMap = map[string]string{}

func init() {
usr, err := user.Current()
Expand All @@ -38,21 +40,49 @@ func init() {
}
}

func InitAppMap() {
res := beego.AppConfig.String("appMap")
if res != "" {
err := json.Unmarshal([]byte(res), &appMap)
if err != nil {
panic(err)
}
}
}

func getMappedName(name string) string {
for k, v := range appMap {
if v != "cc" {
if name == k {
return v
}
} else {
name = strings.Replace(name, k, v, 1)
return name
}
}
return name
}

func GetRepoPath(name string) string {
name = getMappedName(name)
appDir := beego.AppConfig.String("appDir")
res := filepath.Join(appDir, name)
return res
}

func getCodeAppConfPath(name string) string {
name = getMappedName(name)
appDir := beego.AppConfig.String("appDir")
return fmt.Sprintf("%s/%s/conf/app.conf", appDir, name)
}

func getBatPath(name string) string {
name = getMappedName(name)
return fmt.Sprintf("C:/Users/%s/Desktop/run/%s.bat", username, name)
}

func getShortcutPath(name string) string {
name = getMappedName(name)
return fmt.Sprintf("C:/Users/%s/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup/%s.bat - %s.lnk", username, name, getShortcut())
}

0 comments on commit 79d5ea1

Please sign in to comment.