route_exist returns both bool and err-msg now
This commit is contained in:
parent
825599b8c8
commit
4ada419514
|
@ -24,8 +24,9 @@ pub fn run_parse() []Route {
|
||||||
|
|
||||||
routes := get_routes_from_config()
|
routes := get_routes_from_config()
|
||||||
for route in routes {
|
for route in routes {
|
||||||
if !route_exist(route) {
|
ok, err := route_exist(route)
|
||||||
eprintln('route ${route.controller}/${route.function} not found')
|
if !ok {
|
||||||
|
eprintln(err)
|
||||||
exit(1)
|
exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,25 +34,23 @@ pub fn run_parse() []Route {
|
||||||
return routes
|
return routes
|
||||||
}
|
}
|
||||||
|
|
||||||
fn route_exist(route Route) bool {
|
fn route_exist(route Route) (bool,string) {
|
||||||
file := 'Controllers/${route.controller}.v'
|
file := 'Controllers/${route.controller}.v'
|
||||||
if !os.exists(file) {
|
if !os.exists(file) {
|
||||||
eprintln('could not find $file')
|
|
||||||
|
|
||||||
return false
|
return false, 'could not find $file'
|
||||||
}
|
}
|
||||||
file_content := os.read_file(file) or {
|
file_content := os.read_file(file) or {
|
||||||
eprintln('could not read $file')
|
|
||||||
|
|
||||||
return false
|
return false, 'could not read $file'
|
||||||
}
|
}
|
||||||
|
|
||||||
if !file_content.contains('fn ${route.function}()') {
|
if !file_content.contains('fn ${route.function}()') {
|
||||||
|
|
||||||
return false
|
return false, '${route.function} not properly defined'
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true, ''
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_routes_from_config() []Route {
|
fn get_routes_from_config() []Route {
|
||||||
|
|
Loading…
Reference in New Issue