AzLearn

النشر والإنتاج

Deployment

مشروع ~30 دقيقة

النشر والإنتاج — Deployment

هذا الدرس الأخير يجمع كل شيء — كيف تأخذ تطبيق Go من جهازك إلى الإنتاج بشكل موثوق ومُراقب.

CI/CD مع GitHub Actions

main.go

Makefile للمشروع

main.go

الإيقاف اللطيف — Graceful Shutdown

عند إيقاف الخادم، يجب إنهاء الطلبات الحالية قبل الإغلاق:

main.go

الكود الحقيقي للإيقاف اللطيف

func main() {
    srv := &http.Server{Addr: ":8080", Handler: router}

    // تشغيل في goroutine — Run in goroutine
    go func() {
        if err := srv.ListenAndServe(); err != http.ErrServerClosed {
            log.Fatal(err)
        }
    }()

    // انتظار إشارة الإيقاف — Wait for stop signal
    quit := make(chan os.Signal, 1)
    signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
    <-quit

    // إيقاف لطيف مع مهلة — Graceful shutdown with timeout
    ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
    defer cancel()
    srv.Shutdown(ctx)
}

التصحيح بـ pprof — Profiling

main.go

systemd — تشغيل كخدمة

main.go

نظرة على الخدمات المصغرة — Microservices Overview

main.go
تحدي — Challenge