~repos /gromer

#golang#htmx#ssr

git clone https://pyrossh.dev/repos/gromer.git

gromer is a framework and cli to build multipage web apps in golang using htmx and alpinejs.


52b06bea Peter John

3 years ago
fix package name clash
Files changed (1) hide show
  1. cmd/gromer/main.go +6 -16
cmd/gromer/main.go CHANGED
@@ -68,15 +68,6 @@ func rewritePath(route string) string {
68
68
  return muxRoute.String()
69
69
  }
70
70
 
71
- func rewritePkg(pkg string) string {
72
- arr := strings.Split(pkg, "/")
73
- lastItem := arr[len(arr)-1]
74
- if strings.Contains(lastItem, "_") {
75
- return arr[len(arr)-2] + lastItem
76
- }
77
- return lastItem
78
- }
79
-
80
71
  func lowerFirst(s string) string {
81
72
  for i, v := range s {
82
73
  return string(unicode.ToLower(v)) + s[i+1:]
@@ -84,10 +75,6 @@ func lowerFirst(s string) string {
84
75
  return ""
85
76
  }
86
77
 
87
- func getPackage(src string) string {
88
- return src
89
- }
90
-
91
78
  func main() {
92
79
  moduleName := ""
93
80
  pkgFlag := flag.String("pkg", "", "specify a package name")
@@ -114,13 +101,16 @@ func main() {
114
101
  route := strings.ReplaceAll(filesrc, "pages", "")
115
102
  method := getMethod(route)
116
103
  path := getRoute(method, route)
117
- pkg := getPackage(path)
118
104
  if path == "" { // for index page
119
105
  path = "/"
120
- pkg = "pages"
121
106
  }
107
+ data, err := ioutil.ReadFile(filesrc)
108
+ if err != nil {
109
+ return err
110
+ }
111
+ lines := strings.Split(string(data), "\n")
122
112
  gromer.RouteDefs = append(gromer.RouteDefs, gromer.RouteDefinition{
123
- Pkg: rewritePkg(pkg),
113
+ Pkg: strings.Replace(""+lines[0], "package ", "", 1),
124
114
  PkgPath: getRoute(method, route),
125
115
  Method: method,
126
116
  Path: rewritePath(path),