5
5
## Contents
6
6
7
7
- [ Examples] ( #examples )
8
+ - [ comments] ( #comments )
8
9
- [ print] ( #print )
9
10
- [ arrays] ( #arrays )
10
11
- [ uint8 arrays] ( #uint8-arrays )
18
19
19
20
## Examples
20
21
22
+ All sample code is available in [ examples/] ( examples/ )
23
+
24
+ ### Comments
25
+ ---
26
+
27
+ #### Node.js
28
+
29
+ ``` node
30
+ // this is a line comment
31
+
32
+ /*
33
+ this is a block comment
34
+ */
35
+ ```
36
+
37
+ #### Go
38
+
39
+ ``` go
40
+ package main
41
+
42
+ func main () {
43
+ // this is a line comment
44
+
45
+ /*
46
+ this is a block comment
47
+ */
48
+ }
49
+ ```
50
+
21
51
### Print
22
52
---
23
53
@@ -47,7 +77,7 @@ import "fmt"
47
77
func main () {
48
78
fmt.Println (" hello world" )
49
79
fmt.Printf (" hello %s \n " , " world" )
50
- fmt.Printf (" hello %d %s " , 5 , " worlds" )
80
+ fmt.Printf (" hello %d %s \n " , 5 , " worlds" )
51
81
}
52
82
```
53
83
@@ -362,6 +392,60 @@ Output
362
392
hello world
363
393
```
364
394
395
+ ### http server
396
+ ---
397
+
398
+ #### Node.js
399
+
400
+ ``` node
401
+ const http = require (' http' )
402
+
403
+ function handler (request , response ) {
404
+ response .writeHead (200 , { ' Content-type' : ' text/plan' })
405
+ response .write (' hello world' )
406
+ response .end ()
407
+ }
408
+
409
+ const server = http .createServer (handler)
410
+ server .listen (8080 )
411
+ ```
412
+
413
+ Output
414
+
415
+ ``` bash
416
+ $ curl http://localhost:8080
417
+ hello world
418
+ ```
419
+
420
+ #### Go
421
+
422
+ ``` go
423
+ package main
424
+
425
+ import (
426
+ " net/http"
427
+ )
428
+
429
+ func handler (w http .ResponseWriter , r *http .Request ) {
430
+ w.WriteHeader (200 )
431
+ w.Write ([]byte (" hello world" ))
432
+ }
433
+
434
+ func main () {
435
+ http.HandleFunc (" /" , handler)
436
+ if err := http.ListenAndServe (" :8080" , nil ); err != nil {
437
+ panic (err)
438
+ }
439
+ }
440
+ ```
441
+
442
+ Output
443
+
444
+ ``` bash
445
+ $ curl http://localhost:8080
446
+ hello world
447
+ ```
448
+
365
449
366
450
<!--
367
451
#### Node.js
@@ -385,6 +469,6 @@ Output
385
469
```
386
470
-->
387
471
388
- # License
472
+ ## License
389
473
390
474
[ MIT] ( LICENSE )
0 commit comments