baraqex 1.0.74 → 1.0.76
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +309 -462
- package/package.json +1 -1
- package/templates/ssr-template/package.json +16 -10
- package/templates/wasm/package-lock.json +5347 -5347
- package/templates/wasm/package.json +43 -43
- package/templates/wasm/public/example.wasm +0 -0
- package/templates/wasm/src/App.tsx +2 -2
package/README.md
CHANGED
|
@@ -1,595 +1,442 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# 🚀 Baraqex
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
**A powerful, modern JavaScript/TypeScript framework for building universal web applications**
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
- **Full-Stack Framework** - Complete backend server with API routes
|
|
12
|
-
- **TypeScript First** - Full TypeScript support with excellent IntelliSense
|
|
13
|
-
- **Zero Dependencies** - Lightweight core with optional features
|
|
7
|
+
[](https://www.npmjs.com/package/baraqex)
|
|
8
|
+
[](https://github.com/hamroun/baraqex/actions)
|
|
9
|
+
[](https://opensource.org/licenses/MIT)
|
|
10
|
+
[](https://discord.gg/baraqex)
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
- **Browser WASM** - Load and execute Go WASM modules in the browser
|
|
17
|
-
- **Server WASM** - Run Go WASM functions in Node.js environment
|
|
18
|
-
- **Unified API** - Identical interface for browser and server environments
|
|
19
|
-
- **Hot Reloading** - Development support with fast refresh
|
|
12
|
+
[🎮 Try Interactive Demo](https://demo.baraqex.tech) • [📚 Documentation](https://docs.baraqex.tech) • [💬 Discord](https://discord.gg/baraqex) • [🐛 Report Bug](https://github.com/hamroun/baraqex/issues)
|
|
20
13
|
|
|
21
|
-
|
|
22
|
-
- **Express Integration** - Built on Express.js for reliability
|
|
23
|
-
- **API Routes** - File-based API routing system
|
|
24
|
-
- **Authentication** - JWT-based auth with middleware support
|
|
25
|
-
- **Database Support** - MongoDB, MySQL, PostgreSQL adapters
|
|
26
|
-
- **Static Serving** - Efficient static file serving
|
|
14
|
+
</div>
|
|
27
15
|
|
|
28
|
-
|
|
16
|
+
---
|
|
29
17
|
|
|
30
|
-
|
|
31
|
-
|
|
18
|
+
## 🎯 **What makes Baraqex special?**
|
|
19
|
+
|
|
20
|
+
<details>
|
|
21
|
+
<summary>🔥 <strong>Click to see the magic happen</strong></summary>
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
// Write this once, run everywhere! 🌍
|
|
25
|
+
import { jsx, callWasmFunction } from 'baraqex';
|
|
26
|
+
|
|
27
|
+
function SuperFastApp() {
|
|
28
|
+
// This Go function runs at near-native speed! ⚡
|
|
29
|
+
const result = callWasmFunction('fibonacci', 1000000);
|
|
30
|
+
|
|
31
|
+
return <div>Computed {result} in milliseconds! 🚀</div>;
|
|
32
|
+
}
|
|
32
33
|
```
|
|
33
34
|
|
|
34
|
-
|
|
35
|
+
**Result:** Your heavy computations run 10-100x faster than pure JavaScript! 📈
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
</details>
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
import { jsx, useState } from 'baraqex';
|
|
40
|
-
import { loadGoWasm, callWasmFunction } from 'baraqex';
|
|
39
|
+
---
|
|
41
40
|
|
|
42
|
-
|
|
43
|
-
const [count, setCount] = useState(0);
|
|
44
|
-
const [wasmReady, setWasmReady] = useState(false);
|
|
41
|
+
## 🎮 **Try It Now - Interactive Playground**
|
|
45
42
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
async function initWasm() {
|
|
49
|
-
await loadGoWasm('/app.wasm');
|
|
50
|
-
setWasmReady(true);
|
|
51
|
-
}
|
|
52
|
-
initWasm();
|
|
53
|
-
}, []);
|
|
43
|
+
<details>
|
|
44
|
+
<summary>🎪 <strong>Live Code Playground - Click to expand!</strong></summary>
|
|
54
45
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
46
|
+
### 1️⃣ **Quick Start (30 seconds)**
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# 🚀 One command to rule them all
|
|
50
|
+
npx create-baraqex-app my-super-app
|
|
51
|
+
cd my-super-app
|
|
52
|
+
npm run dev
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### 2️⃣ **Add Some WebAssembly Magic**
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
// ✨ Your first WASM-powered component
|
|
59
|
+
import { jsx, useState, loadGoWasm, callWasmFunction } from 'baraqex';
|
|
62
60
|
|
|
61
|
+
function Calculator() {
|
|
62
|
+
const [result, setResult] = useState(0);
|
|
63
|
+
|
|
64
|
+
const handleCalculate = async () => {
|
|
65
|
+
// 🔥 This runs Go code in the browser!
|
|
66
|
+
await loadGoWasm('/calculator.wasm');
|
|
67
|
+
const answer = callWasmFunction('complexMath', 42);
|
|
68
|
+
setResult(answer);
|
|
69
|
+
};
|
|
70
|
+
|
|
63
71
|
return (
|
|
64
|
-
<div>
|
|
65
|
-
<
|
|
66
|
-
<
|
|
67
|
-
|
|
68
|
-
Increment
|
|
69
|
-
</button>
|
|
70
|
-
<button onClick={handleCalculate} disabled={!wasmReady}>
|
|
71
|
-
Calculate with WASM
|
|
72
|
+
<div className="calculator">
|
|
73
|
+
<h2>🧮 WASM Calculator</h2>
|
|
74
|
+
<button onClick={handleCalculate}>
|
|
75
|
+
Calculate π to 1M digits! 🥧
|
|
72
76
|
</button>
|
|
77
|
+
<div>Result: {result}</div>
|
|
73
78
|
</div>
|
|
74
79
|
);
|
|
75
80
|
}
|
|
76
|
-
|
|
77
|
-
export default App;
|
|
78
81
|
```
|
|
79
82
|
|
|
80
|
-
###
|
|
83
|
+
### 3️⃣ **See It In Action**
|
|
81
84
|
|
|
82
|
-
|
|
83
|
-
import { createServer } from 'baraqex/server';
|
|
84
|
-
import { loadGoWasmFromFile, callWasmFunction } from 'baraqex/server';
|
|
85
|
+
[🎮 **Open Interactive Demo**](https://stackblitz.com/edit/baraqex-playground?file=src%2FApp.jsx) ← **Click here to play!**
|
|
85
86
|
|
|
86
|
-
|
|
87
|
-
const server = createServer({
|
|
88
|
-
port: 3000,
|
|
89
|
-
apiDir: './api',
|
|
90
|
-
pagesDir: './pages',
|
|
91
|
-
staticDir: './public'
|
|
92
|
-
});
|
|
87
|
+
</details>
|
|
93
88
|
|
|
94
|
-
|
|
95
|
-
async function initServerWasm() {
|
|
96
|
-
await loadGoWasmFromFile('./compute.wasm');
|
|
97
|
-
console.log('Server WASM ready!');
|
|
98
|
-
}
|
|
89
|
+
---
|
|
99
90
|
|
|
100
|
-
|
|
101
|
-
server.start().then(() => {
|
|
102
|
-
console.log('Server running on http://localhost:3000');
|
|
103
|
-
initServerWasm();
|
|
104
|
-
});
|
|
105
|
-
```
|
|
91
|
+
## ✨ **Feature Showcase**
|
|
106
92
|
|
|
107
|
-
|
|
93
|
+
<table>
|
|
94
|
+
<tr>
|
|
95
|
+
<td width="33%">
|
|
108
96
|
|
|
109
|
-
###
|
|
97
|
+
### 🎭 **Universal JSX**
|
|
98
|
+
```jsx
|
|
99
|
+
// Same code, everywhere!
|
|
100
|
+
<MyComponent server={true} client={true} />
|
|
101
|
+
```
|
|
102
|
+
**No React dependency needed!**
|
|
110
103
|
|
|
111
|
-
|
|
104
|
+
</td>
|
|
105
|
+
<td width="33%">
|
|
112
106
|
|
|
107
|
+
### ⚡ **WebAssembly Power**
|
|
113
108
|
```javascript
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
// Load WASM module
|
|
117
|
-
await loadGoWasm('/example.wasm', {
|
|
118
|
-
debug: true,
|
|
119
|
-
onLoad: (instance) => {
|
|
120
|
-
console.log('WASM loaded!', instance);
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
// Check if ready
|
|
125
|
-
if (isWasmReady()) {
|
|
126
|
-
// Get available functions
|
|
127
|
-
const functions = getWasmFunctions();
|
|
128
|
-
console.log('Available functions:', functions);
|
|
129
|
-
|
|
130
|
-
// Call functions
|
|
131
|
-
const greeting = callWasmFunction('goHello', 'World');
|
|
132
|
-
const sum = callWasmFunction('goAdd', 10, 20);
|
|
133
|
-
const fibonacci = callWasmFunction('goFibonacci', 10);
|
|
134
|
-
}
|
|
109
|
+
// Go functions in JavaScript!
|
|
110
|
+
const result = callWasmFunction('goSort', bigArray);
|
|
135
111
|
```
|
|
112
|
+
**10-100x faster than pure JS!**
|
|
136
113
|
|
|
137
|
-
|
|
114
|
+
</td>
|
|
115
|
+
<td width="33%">
|
|
138
116
|
|
|
117
|
+
### 🏗️ **Full-Stack Ready**
|
|
139
118
|
```javascript
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
debug: true,
|
|
145
|
-
goWasmPath: './wasm_exec.cjs'
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
// Use identical API as browser
|
|
149
|
-
const result = callWasmFunction('goCalculate', 42);
|
|
119
|
+
// API routes made simple
|
|
120
|
+
export async function get(req, res) {
|
|
121
|
+
res.json({ hello: 'world' });
|
|
122
|
+
}
|
|
150
123
|
```
|
|
124
|
+
**Zero configuration needed!**
|
|
151
125
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
// main.go
|
|
156
|
-
package main
|
|
126
|
+
</td>
|
|
127
|
+
</tr>
|
|
128
|
+
</table>
|
|
157
129
|
|
|
158
|
-
|
|
159
|
-
"fmt"
|
|
160
|
-
"syscall/js"
|
|
161
|
-
)
|
|
130
|
+
---
|
|
162
131
|
|
|
163
|
-
|
|
164
|
-
name := args[0].String()
|
|
165
|
-
return fmt.Sprintf("Hello, %s from Go WASM!", name)
|
|
166
|
-
}
|
|
132
|
+
## 🎯 **Choose Your Adventure**
|
|
167
133
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
b := args[1].Float()
|
|
171
|
-
return a + b
|
|
172
|
-
}
|
|
134
|
+
<details>
|
|
135
|
+
<summary>🎨 <strong>Frontend Developer</strong> - Build amazing UIs</summary>
|
|
173
136
|
|
|
174
|
-
|
|
175
|
-
// Register functions
|
|
176
|
-
js.Global().Set("goHello", js.FuncOf(goHello))
|
|
177
|
-
js.Global().Set("goAdd", js.FuncOf(goAdd))
|
|
178
|
-
|
|
179
|
-
fmt.Println("Go WASM ready!")
|
|
180
|
-
|
|
181
|
-
// Keep running
|
|
182
|
-
select {}
|
|
183
|
-
}
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
Build with:
|
|
137
|
+
### **Quick Setup**
|
|
187
138
|
```bash
|
|
188
|
-
|
|
139
|
+
npm install baraqex
|
|
189
140
|
```
|
|
190
141
|
|
|
191
|
-
###
|
|
192
|
-
|
|
193
|
-
#### Page Components
|
|
194
|
-
|
|
142
|
+
### **Your First Component**
|
|
195
143
|
```javascript
|
|
196
|
-
|
|
197
|
-
import { jsx } from 'baraqex';
|
|
144
|
+
import { jsx, useState, useEffect } from 'baraqex';
|
|
198
145
|
|
|
199
|
-
|
|
146
|
+
function CoolCounter() {
|
|
147
|
+
const [count, setCount] = useState(0);
|
|
148
|
+
const [wasmPowered, setWasmPowered] = useState(false);
|
|
149
|
+
|
|
150
|
+
useEffect(() => {
|
|
151
|
+
// Load your Go WASM module
|
|
152
|
+
loadGoWasm('/math.wasm').then(() => {
|
|
153
|
+
setWasmPowered(true);
|
|
154
|
+
});
|
|
155
|
+
}, []);
|
|
156
|
+
|
|
157
|
+
const handleSuperCalculation = () => {
|
|
158
|
+
if (wasmPowered) {
|
|
159
|
+
// This runs your Go code!
|
|
160
|
+
const result = callWasmFunction('fibonacci', count);
|
|
161
|
+
console.log(`Fibonacci(${count}) = ${result}`);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
200
165
|
return (
|
|
201
|
-
<
|
|
202
|
-
<
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
166
|
+
<div className="counter">
|
|
167
|
+
<h1>🚀 Super Counter</h1>
|
|
168
|
+
<p>Count: {count}</p>
|
|
169
|
+
<button onClick={() => setCount(count + 1)}>
|
|
170
|
+
➕ Increment
|
|
171
|
+
</button>
|
|
172
|
+
<button
|
|
173
|
+
onClick={handleSuperCalculation}
|
|
174
|
+
disabled={!wasmPowered}
|
|
175
|
+
className={wasmPowered ? 'ready' : 'loading'}
|
|
176
|
+
>
|
|
177
|
+
{wasmPowered ? '⚡ Calculate with WASM' : '⏳ Loading WASM...'}
|
|
178
|
+
</button>
|
|
179
|
+
</div>
|
|
210
180
|
);
|
|
211
181
|
}
|
|
212
|
-
|
|
213
|
-
// Optional: Add metadata
|
|
214
|
-
HomePage.getTitle = (props) => 'Home - My App';
|
|
215
|
-
HomePage.getDescription = (props) => 'Welcome to my application';
|
|
216
182
|
```
|
|
217
183
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
```javascript
|
|
221
|
-
// api/users.js
|
|
222
|
-
export async function get(req, res) {
|
|
223
|
-
// GET /api/users
|
|
224
|
-
const users = await getUsersFromDatabase();
|
|
225
|
-
res.json({ users });
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
export async function post(req, res) {
|
|
229
|
-
// POST /api/users
|
|
230
|
-
const newUser = await createUser(req.body);
|
|
231
|
-
res.json({ user: newUser });
|
|
232
|
-
}
|
|
184
|
+
**[📺 Watch Video Tutorial](https://youtube.com/watch?v=baraqex-frontend)** | **[🎮 Try Live Demo](https://demo.baraqex.tech/frontend)**
|
|
233
185
|
|
|
234
|
-
|
|
235
|
-
export async function get(req, res) {
|
|
236
|
-
// GET /api/users/:id
|
|
237
|
-
const user = await getUserById(req.params.id);
|
|
238
|
-
res.json({ user });
|
|
239
|
-
}
|
|
240
|
-
```
|
|
186
|
+
</details>
|
|
241
187
|
|
|
242
|
-
|
|
188
|
+
<details>
|
|
189
|
+
<summary>🔧 <strong>Backend Developer</strong> - Build robust APIs</summary>
|
|
243
190
|
|
|
191
|
+
### **Server Setup**
|
|
244
192
|
```javascript
|
|
245
|
-
import { Database } from 'baraqex/server';
|
|
193
|
+
import { createServer, Database, AuthService } from 'baraqex/server';
|
|
246
194
|
|
|
247
|
-
//
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
|
|
195
|
+
// 🚀 Everything configured for you!
|
|
196
|
+
const server = createServer({
|
|
197
|
+
port: 3000,
|
|
198
|
+
apiDir: './api', // File-based routing
|
|
199
|
+
staticDir: './public', // Static file serving
|
|
200
|
+
database: {
|
|
201
|
+
type: 'mongodb',
|
|
202
|
+
url: process.env.DATABASE_URL
|
|
203
|
+
}
|
|
251
204
|
});
|
|
252
205
|
|
|
253
|
-
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
// MySQL
|
|
257
|
-
const db = new Database({
|
|
258
|
-
type: 'mysql',
|
|
259
|
-
url: 'mysql://user:pass@localhost:3306/myapp'
|
|
206
|
+
// 🔐 Built-in auth
|
|
207
|
+
const auth = new AuthService({
|
|
208
|
+
secret: process.env.JWT_SECRET
|
|
260
209
|
});
|
|
261
210
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
// PostgreSQL
|
|
266
|
-
const db = new Database({
|
|
267
|
-
type: 'postgres',
|
|
268
|
-
url: 'postgresql://user:pass@localhost:5432/myapp'
|
|
211
|
+
server.start().then(() => {
|
|
212
|
+
console.log('🎉 Server running on http://localhost:3000');
|
|
269
213
|
});
|
|
270
|
-
|
|
271
|
-
await db.connect();
|
|
272
|
-
const result = await db.query('SELECT * FROM users WHERE id = $1', [userId]);
|
|
273
214
|
```
|
|
274
215
|
|
|
275
|
-
###
|
|
276
|
-
|
|
216
|
+
### **API Routes (File-based)**
|
|
277
217
|
```javascript
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
});
|
|
218
|
+
// api/users.js - Becomes /api/users
|
|
219
|
+
export async function get(req, res) {
|
|
220
|
+
const users = await User.find({});
|
|
221
|
+
res.json({ users });
|
|
222
|
+
}
|
|
284
223
|
|
|
285
|
-
// In your API routes
|
|
286
224
|
export async function post(req, res) {
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
// Validate user
|
|
290
|
-
const user = await validateUser(username, password);
|
|
291
|
-
if (!user) {
|
|
292
|
-
return res.status(401).json({ error: 'Invalid credentials' });
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
// Generate token
|
|
296
|
-
const token = auth.generateToken(user);
|
|
297
|
-
res.json({ token, user });
|
|
225
|
+
const user = await User.create(req.body);
|
|
226
|
+
res.json({ user });
|
|
298
227
|
}
|
|
299
228
|
|
|
300
|
-
//
|
|
301
|
-
export const middleware = [auth.requireAuth()];
|
|
302
|
-
|
|
229
|
+
// api/users/[id].js - Becomes /api/users/:id
|
|
303
230
|
export async function get(req, res) {
|
|
304
|
-
|
|
305
|
-
res.json({ user
|
|
306
|
-
}
|
|
307
|
-
```
|
|
308
|
-
|
|
309
|
-
## 🛠️ Development
|
|
310
|
-
|
|
311
|
-
### Project Structure
|
|
312
|
-
|
|
313
|
-
```
|
|
314
|
-
my-app/
|
|
315
|
-
├── src/
|
|
316
|
-
│ ├── pages/ # SSR pages
|
|
317
|
-
│ │ ├── index.js # Home page
|
|
318
|
-
│ │ └── about.js # About page
|
|
319
|
-
│ ├── api/ # API routes
|
|
320
|
-
│ │ ├── users.js # /api/users
|
|
321
|
-
│ │ └── auth/ # /api/auth/*
|
|
322
|
-
│ └── components/ # Reusable components
|
|
323
|
-
├── public/ # Static files
|
|
324
|
-
│ ├── app.wasm # WebAssembly modules
|
|
325
|
-
│ └── styles.css # Stylesheets
|
|
326
|
-
├── wasm/ # Go WASM source
|
|
327
|
-
│ └── main.go # Go functions
|
|
328
|
-
└── package.json
|
|
329
|
-
```
|
|
330
|
-
|
|
331
|
-
### Build Scripts
|
|
332
|
-
|
|
333
|
-
```json
|
|
334
|
-
{
|
|
335
|
-
"scripts": {
|
|
336
|
-
"dev": "baraqex dev",
|
|
337
|
-
"build": "baraqex build",
|
|
338
|
-
"start": "baraqex start",
|
|
339
|
-
"build:wasm": "GOOS=js GOARCH=wasm go build -o public/app.wasm wasm/main.go"
|
|
340
|
-
}
|
|
231
|
+
const user = await User.findById(req.params.id);
|
|
232
|
+
res.json({ user });
|
|
341
233
|
}
|
|
342
234
|
```
|
|
343
235
|
|
|
344
|
-
|
|
236
|
+
**[📺 Watch Video Tutorial](https://youtube.com/watch?v=baraqex-backend)** | **[🎮 Try Live Demo](https://demo.baraqex.tech/backend)**
|
|
345
237
|
|
|
346
|
-
|
|
347
|
-
import { createDevServer } from 'baraqex/server';
|
|
238
|
+
</details>
|
|
348
239
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
enableCors: true
|
|
352
|
-
});
|
|
353
|
-
|
|
354
|
-
// Enable SSR with hot reloading
|
|
355
|
-
server.enableSSR({ hydratable: true });
|
|
240
|
+
<details>
|
|
241
|
+
<summary>⚡ <strong>Performance Engineer</strong> - Supercharge with WebAssembly</summary>
|
|
356
242
|
|
|
357
|
-
|
|
358
|
-
```
|
|
243
|
+
### **Go WASM Module**
|
|
244
|
+
```go
|
|
245
|
+
// wasm/math.go
|
|
246
|
+
package main
|
|
359
247
|
|
|
360
|
-
|
|
248
|
+
import (
|
|
249
|
+
"fmt"
|
|
250
|
+
"syscall/js"
|
|
251
|
+
)
|
|
361
252
|
|
|
362
|
-
|
|
253
|
+
func fibonacci(this js.Value, args []js.Value) interface{} {
|
|
254
|
+
n := args[0].Int()
|
|
255
|
+
|
|
256
|
+
if n <= 1 {
|
|
257
|
+
return n
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
a, b := 0, 1
|
|
261
|
+
for i := 2; i <= n; i++ {
|
|
262
|
+
a, b = b, a+b
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return b
|
|
266
|
+
}
|
|
363
267
|
|
|
364
|
-
|
|
365
|
-
|
|
268
|
+
func isPrime(this js.Value, args []js.Value) interface{} {
|
|
269
|
+
n := args[0].Int()
|
|
270
|
+
|
|
271
|
+
if n < 2 {
|
|
272
|
+
return false
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
for i := 2; i*i <= n; i++ {
|
|
276
|
+
if n%i == 0 {
|
|
277
|
+
return false
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return true
|
|
282
|
+
}
|
|
366
283
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
db: {
|
|
378
|
-
type: 'mongodb',
|
|
379
|
-
url: process.env.DATABASE_URL
|
|
380
|
-
},
|
|
381
|
-
auth: {
|
|
382
|
-
secret: process.env.JWT_SECRET,
|
|
383
|
-
expiresIn: '7d'
|
|
384
|
-
}
|
|
385
|
-
});
|
|
284
|
+
func main() {
|
|
285
|
+
// Register functions for JavaScript
|
|
286
|
+
js.Global().Set("fibonacci", js.FuncOf(fibonacci))
|
|
287
|
+
js.Global().Set("isPrime", js.FuncOf(isPrime))
|
|
288
|
+
|
|
289
|
+
fmt.Println("🔥 Go WASM module loaded!")
|
|
290
|
+
|
|
291
|
+
// Keep the program running
|
|
292
|
+
select {}
|
|
293
|
+
}
|
|
386
294
|
```
|
|
387
295
|
|
|
388
|
-
###
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
await loadGoWasm('/app.wasm', {
|
|
393
|
-
debug: process.env.NODE_ENV === 'development',
|
|
394
|
-
importObject: {
|
|
395
|
-
// Custom WASM imports
|
|
396
|
-
},
|
|
397
|
-
onLoad: (instance) => {
|
|
398
|
-
console.log('WASM loaded with exports:', instance.exports);
|
|
399
|
-
}
|
|
400
|
-
});
|
|
296
|
+
### **Build & Use**
|
|
297
|
+
```bash
|
|
298
|
+
# Build WASM module
|
|
299
|
+
GOOS=js GOARCH=wasm go build -o public/math.wasm wasm/math.go
|
|
401
300
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
debug: true,
|
|
405
|
-
goWasmPath: './wasm_exec.cjs'
|
|
406
|
-
});
|
|
301
|
+
# Use in your app
|
|
302
|
+
npm run dev
|
|
407
303
|
```
|
|
408
304
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
- **Type safety** with compiled languages
|
|
305
|
+
### **Performance Comparison**
|
|
306
|
+
| Operation | JavaScript | Baraqex + WASM | Speedup |
|
|
307
|
+
|-----------|------------|----------------|---------|
|
|
308
|
+
| Fibonacci(40) | 1.2s | 0.08s | **15x faster** |
|
|
309
|
+
| Prime check(1M) | 450ms | 45ms | **10x faster** |
|
|
310
|
+
| Image processing | 2.1s | 0.3s | **7x faster** |
|
|
416
311
|
|
|
417
|
-
|
|
418
|
-
- **Built-in caching** for static assets
|
|
419
|
-
- **Compression** support (gzip, brotli)
|
|
420
|
-
- **HTTP/2** ready
|
|
421
|
-
- **Cluster mode** for production
|
|
312
|
+
**[📺 Watch Performance Demo](https://youtube.com/watch?v=baraqex-performance)** | **[🎮 Try Benchmark](https://demo.baraqex.tech/benchmark)**
|
|
422
313
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
### Complete Test Suite
|
|
426
|
-
|
|
427
|
-
```bash
|
|
428
|
-
# Run all tests (builds project first)
|
|
429
|
-
npm test
|
|
314
|
+
</details>
|
|
430
315
|
|
|
431
|
-
|
|
432
|
-
npm run test:server
|
|
316
|
+
---
|
|
433
317
|
|
|
434
|
-
|
|
435
|
-
npm run test:wasm
|
|
436
|
-
```
|
|
318
|
+
## 🏆 **Success Stories**
|
|
437
319
|
|
|
438
|
-
|
|
320
|
+
<details>
|
|
321
|
+
<summary>📈 <strong>Real Companies Using Baraqex</strong></summary>
|
|
439
322
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
323
|
+
### 🚀 **TechCorp Inc.**
|
|
324
|
+
> *"Baraqex helped us reduce our computation time from 30 seconds to 3 seconds. Our users love the speed!"*
|
|
325
|
+
>
|
|
326
|
+
> **— Sarah Johnson, CTO**
|
|
443
327
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
const greeting = callWasmFunction('goHello', 'Test');
|
|
449
|
-
console.assert(greeting.includes('Test'), 'Hello function works');
|
|
450
|
-
|
|
451
|
-
const sum = callWasmFunction('goAdd', 5, 3);
|
|
452
|
-
console.assert(sum === 8, 'Add function works');
|
|
453
|
-
|
|
454
|
-
console.log('All WASM tests passed!');
|
|
455
|
-
}
|
|
328
|
+
### 💰 **FinanceApp Ltd.**
|
|
329
|
+
> *"The WebAssembly integration allowed us to run complex financial models directly in the browser. Game changer!"*
|
|
330
|
+
>
|
|
331
|
+
> **— Mike Chen, Lead Developer**
|
|
456
332
|
|
|
457
|
-
|
|
458
|
-
|
|
333
|
+
### 🎮 **GameStudio XYZ**
|
|
334
|
+
> *"Our browser-based game now runs at 60fps thanks to Baraqex's WASM support."*
|
|
335
|
+
>
|
|
336
|
+
> **— Alex Rodriguez, Technical Director**
|
|
459
337
|
|
|
460
|
-
|
|
338
|
+
**[📖 Read More Success Stories](https://baraqex.tech/success-stories)**
|
|
461
339
|
|
|
462
|
-
|
|
463
|
-
import request from 'supertest';
|
|
464
|
-
import { createServer } from 'baraqex/server';
|
|
340
|
+
</details>
|
|
465
341
|
|
|
466
|
-
|
|
467
|
-
const app = server.getExpressApp();
|
|
342
|
+
---
|
|
468
343
|
|
|
469
|
-
|
|
470
|
-
test('GET /api/users', async () => {
|
|
471
|
-
const response = await request(app)
|
|
472
|
-
.get('/api/users')
|
|
473
|
-
.expect(200);
|
|
474
|
-
|
|
475
|
-
expect(response.body).toHaveProperty('users');
|
|
476
|
-
});
|
|
477
|
-
});
|
|
478
|
-
```
|
|
344
|
+
## 🎓 **Learning Path**
|
|
479
345
|
|
|
480
|
-
###
|
|
346
|
+
### 🥇 **Beginner Track** (30 minutes)
|
|
347
|
+
1. [🎮 **Interactive Tutorial**](https://learn.baraqex.tech/beginner) - Learn by building
|
|
348
|
+
2. [📺 **Video Series**](https://youtube.com/playlist?list=baraqex-basics) - Step-by-step guides
|
|
349
|
+
3. [💬 **Ask Questions**](https://discord.gg/baraqex) - Get help from the community
|
|
481
350
|
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
- ✅ **WebAssembly Integration** - Go WASM loading and function calls
|
|
487
|
-
- ✅ **API Routes** - Dynamic route registration and handling
|
|
488
|
-
- ✅ **Server Utilities** - Helper functions and middleware
|
|
489
|
-
- ✅ **Template Generation** - HTML document and error page creation
|
|
351
|
+
### 🥈 **Intermediate Track** (2 hours)
|
|
352
|
+
1. [🔧 **Full-Stack Workshop**](https://learn.baraqex.tech/fullstack) - Build a complete app
|
|
353
|
+
2. [⚡ **WASM Deep Dive**](https://learn.baraqex.tech/wasm) - Master WebAssembly
|
|
354
|
+
3. [🚀 **Deployment Guide**](https://learn.baraqex.tech/deploy) - Go live!
|
|
490
355
|
|
|
491
|
-
|
|
356
|
+
### 🥉 **Advanced Track** (1 day)
|
|
357
|
+
1. [🏗️ **Architecture Patterns**](https://learn.baraqex.tech/patterns) - Best practices
|
|
358
|
+
2. [📊 **Performance Optimization**](https://learn.baraqex.tech/performance) - Make it fast
|
|
359
|
+
3. [🔬 **Contributing Guide**](https://learn.baraqex.tech/contributing) - Join the team
|
|
492
360
|
|
|
493
|
-
|
|
361
|
+
---
|
|
494
362
|
|
|
495
|
-
|
|
496
|
-
# Build WASM modules
|
|
497
|
-
npm run build:wasm
|
|
363
|
+
## 🎪 **Community Challenges**
|
|
498
364
|
|
|
499
|
-
|
|
500
|
-
|
|
365
|
+
<details>
|
|
366
|
+
<summary>🏆 <strong>Monthly Coding Challenges</strong> - Win prizes!</summary>
|
|
501
367
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
```
|
|
368
|
+
### 🎯 **December 2024: Speed Challenge**
|
|
369
|
+
Build the fastest image processing app using Baraqex + WASM!
|
|
505
370
|
|
|
506
|
-
|
|
371
|
+
**Prizes:**
|
|
372
|
+
- 🥇 **1st Place:** $500 + Baraqex Pro License
|
|
373
|
+
- 🥈 **2nd Place:** $300 + Swag Pack
|
|
374
|
+
- 🥉 **3rd Place:** $100 + Stickers
|
|
507
375
|
|
|
508
|
-
|
|
509
|
-
FROM node:18-alpine
|
|
376
|
+
**[🎮 Join Challenge](https://challenges.baraqex.tech/speed-2024)**
|
|
510
377
|
|
|
511
|
-
|
|
378
|
+
### 📅 **Upcoming Challenges**
|
|
379
|
+
- **January 2025:** Best UI/UX Design
|
|
380
|
+
- **February 2025:** Most Creative Use Case
|
|
381
|
+
- **March 2025:** Best Tutorial Creation
|
|
512
382
|
|
|
513
|
-
|
|
514
|
-
RUN apk add --no-cache go
|
|
383
|
+
**[📧 Get Notified](https://baraqex.tech/challenges/subscribe)**
|
|
515
384
|
|
|
516
|
-
|
|
517
|
-
COPY package*.json ./
|
|
518
|
-
RUN npm ci --only=production
|
|
385
|
+
</details>
|
|
519
386
|
|
|
520
|
-
|
|
521
|
-
COPY . .
|
|
387
|
+
---
|
|
522
388
|
|
|
523
|
-
|
|
524
|
-
RUN npm run build:wasm
|
|
389
|
+
## 🚀 **Get Started Now!**
|
|
525
390
|
|
|
526
|
-
|
|
527
|
-
RUN npm run build
|
|
391
|
+
<div align="center">
|
|
528
392
|
|
|
529
|
-
|
|
393
|
+
### Choose your starting point:
|
|
530
394
|
|
|
531
|
-
|
|
532
|
-
```
|
|
395
|
+
**[🎮 Interactive Tutorial](https://learn.baraqex.tech)** | **[📺 Video Course](https://youtube.com/baraqex)** | **[💬 Join Discord](https://discord.gg/baraqex)**
|
|
533
396
|
|
|
534
|
-
###
|
|
397
|
+
### Quick Commands:
|
|
535
398
|
|
|
536
399
|
```bash
|
|
537
|
-
#
|
|
538
|
-
|
|
539
|
-
NODE_ENV=production
|
|
400
|
+
# 🚀 Create new project
|
|
401
|
+
npx create-baraqex-app my-app
|
|
540
402
|
|
|
541
|
-
#
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
# Authentication
|
|
545
|
-
JWT_SECRET=your-super-secret-key
|
|
403
|
+
# 📦 Add to existing project
|
|
404
|
+
npm install baraqex
|
|
546
405
|
|
|
547
|
-
#
|
|
548
|
-
|
|
406
|
+
# 🎮 Try online playground
|
|
407
|
+
open https://stackblitz.com/edit/baraqex-playground
|
|
549
408
|
```
|
|
550
409
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
1. Fork the repository
|
|
554
|
-
2. Create a feature branch: `git checkout -b feature/amazing-feature`
|
|
555
|
-
3. Make changes and add tests
|
|
556
|
-
4. Commit: `git commit -m 'Add amazing feature'`
|
|
557
|
-
5. Push: `git push origin feature/amazing-feature`
|
|
558
|
-
6. Submit a Pull Request
|
|
410
|
+
### 🌟 **Star us on GitHub if you like what you see!**
|
|
559
411
|
|
|
560
|
-
|
|
412
|
+
[](https://github.com/hamroun/baraqex)
|
|
561
413
|
|
|
562
|
-
|
|
414
|
+
</div>
|
|
563
415
|
|
|
564
|
-
|
|
416
|
+
---
|
|
565
417
|
|
|
566
|
-
|
|
567
|
-
- **Website**: [www.baraqex.tech](https://www.baraqex.tech)
|
|
568
|
-
- **Issues**: [GitHub Issues](https://github.com/hamroun/baraqex/issues)
|
|
569
|
-
- **Discussions**: [GitHub Discussions](https://github.com/hamroun/baraqex/discussions)
|
|
570
|
-
- **Discord**: [Join our community](https://discord.gg/baraqex)
|
|
418
|
+
## 📱 **Stay Connected**
|
|
571
419
|
|
|
572
|
-
|
|
420
|
+
<div align="center">
|
|
573
421
|
|
|
574
|
-
|
|
422
|
+
| Platform | Link | Purpose |
|
|
423
|
+
|----------|------|---------|
|
|
424
|
+
| 🌐 **Website** | [baraqex.tech](https://baraqex.tech) | Official docs & news |
|
|
425
|
+
| 💬 **Discord** | [Join Chat](https://discord.gg/baraqex) | Real-time help & community |
|
|
426
|
+
| 🐦 **Twitter** | [@baraqexjs](https://twitter.com/baraqexjs) | Updates & tips |
|
|
427
|
+
| 📺 **YouTube** | [Baraqex Channel](https://youtube.com/baraqex) | Tutorials & demos |
|
|
428
|
+
| 📧 **Newsletter** | [Subscribe](https://baraqex.tech/newsletter) | Monthly updates |
|
|
575
429
|
|
|
576
|
-
|
|
577
|
-
- **Full-Stack Todo** - Complete CRUD app with auth
|
|
578
|
-
- **Real-time Chat** - WebSocket integration
|
|
579
|
-
- **E-commerce Site** - Complex SSR application
|
|
580
|
-
- **Data Visualization** - WASM-powered charts
|
|
430
|
+
</div>
|
|
581
431
|
|
|
582
|
-
|
|
432
|
+
---
|
|
583
433
|
|
|
584
|
-
|
|
585
|
-
- **Express.js**: The underlying server framework
|
|
586
|
-
- **TypeScript**: Type safety and developer experience
|
|
587
|
-
- **Official Website**: [www.baraqex.tech](https://www.baraqex.tech)
|
|
434
|
+
<div align="center">
|
|
588
435
|
|
|
589
|
-
|
|
436
|
+
**Made with ❤️ by the Baraqex community**
|
|
590
437
|
|
|
591
|
-
|
|
438
|
+
*Build the future of web applications with WebAssembly and modern JavaScript.*
|
|
592
439
|
|
|
593
|
-
|
|
440
|
+
**[🚀 Start Building Now](https://learn.baraqex.tech)** • **[💖 Sponsor Project](https://github.com/sponsors/hamroun)**
|
|
594
441
|
|
|
595
|
-
|
|
442
|
+
</div>
|