Skip to content

Commit 01509eb

Browse files
committed
examples update
1 parent 21b3fae commit 01509eb

File tree

6 files changed

+45
-15
lines changed

6 files changed

+45
-15
lines changed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
build:
22
go build -o buglang ./cmd/main.go
33

4+
air:
5+
air --build.cmd="go build -o /tmp/buglang ./cmd/main.go" --build.bin="/tmp/buglang" .
6+
7+
air-fpm:
8+
air --build.cmd="go build -o /tmp/buglang ./cmd/fpm/main.go" --build.bin="/tmp/buglang" .
49

510
.PHONY: build

examples/handlers/user.bug

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11

2-
3-
42
class User(){
53
func init(){
64
this.users = [

examples/index.bug

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import "handlers.root";
88
user = new user.User();
99

1010
router = new routes.Routes();
11-
router.register("/", root.health);
12-
router.register("/users/1", user.detail);
13-
router.register("/users", user.list);
14-
router.register("/users/create", user.create);
11+
router.get("/", root.health);
12+
router.get("/users/1", user.detail);
13+
router.get("/users", user.list);
14+
router.post("/users/create", user.create);
1515

16-
handler = router.get($_REQUEST["Path"]);
17-
println(json.encode(handler()));
16+
handler = router.get_handler();
17+
print(json.encode(handler()));

examples/routes/routes.bug

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,43 @@
1+
import "json";
2+
13
class Routes(){
24
func init(){
3-
this.routes = {};
5+
this.routes = {
6+
"POST": {},
7+
"GET": {},
8+
"PUT": {},
9+
"PATCH": {},
10+
"DELETE": {},
11+
};
12+
}
13+
14+
func post(path, fn){
15+
this.routes["POST"].append(path, fn);
16+
}
17+
18+
func get(path, fn){
19+
this.routes["GET"].append(path, fn);
20+
}
21+
22+
func put(path, fn){
23+
this.routes["PUT"].append(path, fn);
24+
}
25+
26+
func patch(path, fn){
27+
this.routes["PATCH"].append(path, fn);
428
}
529

6-
func register(path, fn){
7-
this.routes.append(path, fn);
30+
func delete(path, fn){
31+
this.routes["DELETE"].append(path, fn);
832
}
933

1034
func list(){
1135
return this.routes;
1236
}
1337

14-
func get(path){
15-
return this.routes[path];
38+
func get_handler(){
39+
var path = $_REQUEST["Path"];
40+
var method = $_REQUEST["Method"]
41+
return this.routes[method][path];
1642
}
1743
}

internal/runtime/interpreter.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,9 @@ func EvalStdModuleStatement(node *parser.StdModuleNode, env *enviroment.Envirome
100100
return nil, nil
101101
}
102102
func EvalModuleStatement(node *parser.ModuleNode, env *enviroment.Enviroment) (any, error) {
103-
scope := enviroment.NewEnv(nil)
104-
std.Load(scope)
103+
// WARNING: buni to'g'irlash kerak module ichida global env ishlatilyapti bu xato
104+
scope := enviroment.NewEnv(env)
105+
// std.Load(scope)
105106
if module := env.Modules.Get(node.Path); module != nil {
106107
return env.DeclareVariable(node.Name, module, node.Line), nil
107108
}

tmp/main

990 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)