"Life is all about sharing. If we are good at something, pass it on." - Mary Berry

Auto reload your Go webserver with Gulp

2019-09-20

When you developp a webserver with Go, you must compile each time you do an update in your code. Well.. this is redundant. With Gulp you can automatize this task… Indeed, when a go file is modified, a task compile the application in the “bin” folder (“gopath/bin”) then another launch the executable (the webserver).

https://medium.com/@etiennerouzeaud/autoreload-your-go-webserver-with-gulp-ee5e231d133d

 1const gulp     = require('gulp'),
 2      util     = require('gulp-util'),
 3      notifier = require('node-notifier'),
 4      child    = require('child_process'),
 5      os       = require('os'),
 6      path     = require('path');
 7
 8var server = 'null'
 9
10function build() {
11    var build = child.spawn('go', ['install']);
12
13    build.stdout.on('data', (data) => {
14        console.log(`stdout: ${data}`);
15    });
16
17    build.stderr.on('data', (data) => {
18        console.error(`stderr: ${data}`);
19    });
20
21    return build;
22}
23
24function spawn(done) {
25    if (server && server != 'null') {
26        server.kill();
27    }
28
29    var path_folder = process.cwd().split(path.sep)
30    var length = path_folder.length
31    var app = path_folder[length - parseInt(1)];
32
33    if (os.platform() == 'win32') {
34        server = child.spawn(app + '.exe')
35    } else {
36        server = child.spawn(app)
37    }
38
39    server.stdout.on('data', (data) => {
40        console.log(`stdout: ${data}`);
41    });
42
43    server.stderr.on('data', (data) => {
44        console.log(`stderr: ${data}`);
45    });
46
47    done();
48}
49
50const serve = gulp.series(build, spawn)
51function watch(done) {
52    gulp.watch(['*.go', '**/*.go'], serve);
53    done();
54}
55
56exports.serve = serve
57exports.watch = watch
58exports.default = gulp.parallel(serve, watch)

Read More...


About

2019-09-19

Hi. I’m Quan. I began my career as a .NET developer but my passion for Linux and open source led me to pursue a career in system administrator. With extensive experience in Linux system administration, I have since transitioned to working as a software engineer. In my spare time, I enjoy teaching my wife how to program to optimize her office tasks.

I am motivated by roles that make a positive impact on people’s lives or offer opportunities to help others.

Read More...


Lavender

2019-06-17

Lavender in Provence Lavender in Provence, France.

Marseille -> Provence: 150km

Xe lạ. Lái không mới nhưng sợ đi số sàn, nhất là đề-pa. Có lần dừng đèn đỏ, cứ “côn ra ga vào” là chết máy, đằng sau bóp còi inh ỏi, người toát mồ hôi. Bình tĩnh nhìn lại thì hóa ra… chưa hạ phanh tay.


Đến những nơi bạn chưa từng đến.
Làm những điều bạn chưa từng làm.
Để có được những trải nghiệm bạn chưa từng có.

Read More...


France

2019-06-15

Eiffel tower Eiffel tower, Paris, France.

Champs-Elysees Boulevard Champs-Elysees boulevard, Paris, France.

X


Hà Nội

2019-02-01

K9 Bách khoa K9 Bach khoa, Hanoi.

Long Bien bridge Long Bien bridge, Hanoi.

Fishing on the West lake West lake, Hanoi.

L’etage cafe L’etage cafe, Hanoi.

Đêm nằm mơ thấy đi tu
Sáng ra tỉnh dậy mùa thu đã về

Ô Quan Chưởng Quan Chuong gate, Hanoi.


Chân ta đi hôn mặt đất nồng ấm

2016-11-28

Father and son in Hakone Father and son in Hakone.

Đáp Shinkansen từ Kyoto. Đến Odawara, gửi vali xong, lơ ngơ đi hỏi đường. Lên xe buýt rồi đi một chuyến tàu nữa mới đến được Hakone. Hơn 7h, trời mưa tầm tã.

Taxi chở về khách sạn. Ấn tượng đầu tiên là ngay cửa ra vào xếp khoảng vài chục đôi dép một cách ngay ngắn. Chủ nhà rất friendly, đầu không tóc, nhìn như một vị hoà thượng trong thiếu lâm tự. Không nói được tiếng Anh, tay lăm lăm con iPad, mỗi khi bên nào cần nói gì thì nhờ Google dịch hộ.

Read More...


Kiyomizu-dera Pagoda

2016-11-26

Kiyomizu-dera pagoda Kiyomizu-dera pagoda, Kyoto, Japan.


Nam Định

2010-05-02

Bếp-Than-Xăng-Dầu

Con cafe

Rạp Tháng Tám

Khoai Dong church Khoai dong church, Namdinh.