|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "strings" |
| 5 | + |
| 6 | + "github.com/coderianx/flint" |
| 7 | +) |
| 8 | + |
| 9 | +// Article struct — Makale verilerini temsil eden yapı |
| 10 | +// This struct represents an article with ID, Title, and Content fields. |
| 11 | +type Article struct { |
| 12 | + ID int `json:"id"` // Makale ID'si — Article ID |
| 13 | + Title string `json:"title"` // Makale başlığı — Article title |
| 14 | + Content string `json:"content"` // Makale içeriği — Article content |
| 15 | +} |
| 16 | + |
| 17 | +func main() { |
| 18 | + // Yeni bir Flint sunucusu başlat |
| 19 | + // Start a new Flint server |
| 20 | + app := flint.NewServer() |
| 21 | + |
| 22 | + // Örnek makale verileri |
| 23 | + // Example article data |
| 24 | + articles := []Article{ |
| 25 | + {ID: 1, Title: "Golang ile Web 1", Content: "Go dilinde web geliştirme örnekleri 1..."}, |
| 26 | + {ID: 2, Title: "Flint Framework Tanıtımı 2", Content: "Flint, hafif bir Go web frameworküdür 2..."}, |
| 27 | + {ID: 3, Title: "JavaScript Temelleri 3", Content: "JavaScript değişkenler, fonksiyonlar 3..."}, |
| 28 | + {ID: 4, Title: "Go Routines ve Concurrency 4", Content: "Go rutinleri ile paralel işler yapma 4..."}, |
| 29 | + {ID: 5, Title: "Web için HTML & CSS 5", Content: "Temel HTML ve CSS stilleri 5..."}, |
| 30 | + {ID: 6, Title: "Golang ile Web 6", Content: "Go dilinde web geliştirme örnekleri 6..."}, |
| 31 | + {ID: 7, Title: "Flint Framework Tanıtımı 7", Content: "Flint, hafif bir Go web frameworküdür 7..."}, |
| 32 | + {ID: 8, Title: "JavaScript Temelleri 8", Content: "JavaScript değişkenler, fonksiyonlar 8..."}, |
| 33 | + {ID: 9, Title: "Go Routines ve Concurrency 9", Content: "Go rutinleri ile paralel işler yapma 9..."}, |
| 34 | + {ID: 10, Title: "Web için HTML & CSS 10", Content: "Temel HTML ve CSS stilleri 10..."}, |
| 35 | + {ID: 11, Title: "Golang ile Web 11", Content: "Go dilinde web geliştirme örnekleri 11..."}, |
| 36 | + {ID: 12, Title: "Flint Framework Tanıtımı 12", Content: "Flint, hafif bir Go web frameworküdür 12..."}, |
| 37 | + {ID: 13, Title: "JavaScript Temelleri 13", Content: "JavaScript değişkenler, fonksiyonlar 13..."}, |
| 38 | + {ID: 14, Title: "Go Routines ve Concurrency 14", Content: "Go rutinleri ile paralel işler yapma 14..."}, |
| 39 | + {ID: 15, Title: "Web için HTML & CSS 15", Content: "Temel HTML ve CSS stilleri 15..."}, |
| 40 | + {ID: 16, Title: "Golang ile Web 16", Content: "Go dilinde web geliştirme örnekleri 16..."}, |
| 41 | + {ID: 17, Title: "Flint Framework Tanıtımı 17", Content: "Flint, hafif bir Go web frameworküdür 17..."}, |
| 42 | + {ID: 18, Title: "JavaScript Temelleri 18", Content: "JavaScript değişkenler, fonksiyonlar 18..."}, |
| 43 | + {ID: 19, Title: "Go Routines ve Concurrency 19", Content: "Go rutinleri ile paralel işler yapma 19..."}, |
| 44 | + {ID: 20, Title: "Web için HTML & CSS 20", Content: "Temel HTML ve CSS stilleri 20..."}, |
| 45 | + {ID: 21, Title: "Golang ile Web 21", Content: "Go dilinde web geliştirme örnekleri 21..."}, |
| 46 | + {ID: 22, Title: "Flint Framework Tanıtımı 22", Content: "Flint, hafif bir Go web frameworküdür 22..."}, |
| 47 | + {ID: 23, Title: "JavaScript Temelleri 23", Content: "JavaScript değişkenler, fonksiyonlar 23..."}, |
| 48 | + {ID: 24, Title: "Go Routines ve Concurrency 24", Content: "Go rutinleri ile paralel işler yapma 24..."}, |
| 49 | + {ID: 25, Title: "Web için HTML & CSS 25", Content: "Temel HTML ve CSS stilleri 25..."}, |
| 50 | + {ID: 26, Title: "Golang ile Web 26", Content: "Go dilinde web geliştirme örnekleri 26..."}, |
| 51 | + {ID: 27, Title: "Flint Framework Tanıtımı 27", Content: "Flint, hafif bir Go web frameworküdür 27..."}, |
| 52 | + {ID: 28, Title: "JavaScript Temelleri 28", Content: "JavaScript değişkenler, fonksiyonlar 28..."}, |
| 53 | + {ID: 29, Title: "Go Routines ve Concurrency 29", Content: "Go rutinleri ile paralel işler yapma 29..."}, |
| 54 | + {ID: 30, Title: "Web için HTML & CSS 30", Content: "Temel HTML ve CSS stilleri 30..."}, |
| 55 | + {ID: 31, Title: "Golang ile Web 31", Content: "Go dilinde web geliştirme örnekleri 31..."}, |
| 56 | + {ID: 32, Title: "Flint Framework Tanıtımı 32", Content: "Flint, hafif bir Go web frameworküdür 32..."}, |
| 57 | + {ID: 33, Title: "JavaScript Temelleri 33", Content: "JavaScript değişkenler, fonksiyonlar 33..."}, |
| 58 | + {ID: 34, Title: "Go Routines ve Concurrency 34", Content: "Go rutinleri ile paralel işler yapma 34..."}, |
| 59 | + {ID: 35, Title: "Web için HTML & CSS 35", Content: "Temel HTML ve CSS stilleri 35..."}, |
| 60 | + {ID: 36, Title: "Golang ile Web 36", Content: "Go dilinde web geliştirme örnekleri 36..."}, |
| 61 | + {ID: 37, Title: "Flint Framework Tanıtımı 37", Content: "Flint, hafif bir Go web frameworküdür 37..."}, |
| 62 | + {ID: 38, Title: "JavaScript Temelleri 38", Content: "JavaScript değişkenler, fonksiyonlar 38..."}, |
| 63 | + {ID: 39, Title: "Go Routines ve Concurrency 39", Content: "Go rutinleri ile paralel işler yapma 39..."}, |
| 64 | + {ID: 40, Title: "Web için HTML & CSS 40", Content: "Temel HTML ve CSS stilleri 40..."}, |
| 65 | + {ID: 41, Title: "Golang ile Web 41", Content: "Go dilinde web geliştirme örnekleri 41..."}, |
| 66 | + {ID: 42, Title: "Flint Framework Tanıtımı 42", Content: "Flint, hafif bir Go web frameworküdür 42..."}, |
| 67 | + {ID: 43, Title: "JavaScript Temelleri 43", Content: "JavaScript değişkenler, fonksiyonlar 43..."}, |
| 68 | + {ID: 44, Title: "Go Routines ve Concurrency 44", Content: "Go rutinleri ile paralel işler yapma 44..."}, |
| 69 | + {ID: 45, Title: "Web için HTML & CSS 45", Content: "Temel HTML ve CSS stilleri 45..."}, |
| 70 | + {ID: 46, Title: "Golang ile Web 46", Content: "Go dilinde web geliştirme örnekleri 46..."}, |
| 71 | + {ID: 47, Title: "Flint Framework Tanıtımı 47", Content: "Flint, hafif bir Go web frameworküdür 47..."}, |
| 72 | + {ID: 48, Title: "JavaScript Temelleri 48", Content: "JavaScript değişkenler, fonksiyonlar 48..."}, |
| 73 | + {ID: 49, Title: "Go Routines ve Concurrency 49", Content: "Go rutinleri ile paralel işler yapma 49..."}, |
| 74 | + {ID: 50, Title: "Web için HTML & CSS 50", Content: "Temel HTML ve CSS stilleri 50..."}, |
| 75 | + // ... |
| 76 | + } |
| 77 | + |
| 78 | + // Ana sayfada statik HTML dosyasını servis et |
| 79 | + // Serve the static HTML file at the root path |
| 80 | + app.Handle("/", func(ctx *flint.Context) { |
| 81 | + ctx.File("./examples/search/index.html") |
| 82 | + }) |
| 83 | + |
| 84 | + // Arama API endpoint'i |
| 85 | + // Search API endpoint |
| 86 | + app.Handle("/api/search", func(ctx *flint.Context) { |
| 87 | + // Sadece GET isteğine izin ver |
| 88 | + // Allow only GET requests |
| 89 | + if !ctx.Get() { |
| 90 | + ctx.String(405, "Method Not Allowed") // 405 — Method Not Allowed |
| 91 | + return |
| 92 | + } |
| 93 | + |
| 94 | + // Query parametre "q" değerini al ve küçük harfe çevir |
| 95 | + // Get the "q" query parameter and convert it to lowercase |
| 96 | + q := strings.ToLower(strings.TrimSpace(ctx.Query("q"))) |
| 97 | + |
| 98 | + // Arama sonuçlarını tutmak için slice |
| 99 | + // Slice to store search results |
| 100 | + var results []Article |
| 101 | + |
| 102 | + // Eğer arama kelimesi boş değilse filtreleme yap |
| 103 | + // If search query is not empty, filter the articles |
| 104 | + if q != "" { |
| 105 | + for _, a := range articles { |
| 106 | + // Başlıkta veya içerikte arama kelimesi geçiyorsa ekle |
| 107 | + // If the search query appears in the title or content, add it to results |
| 108 | + if strings.Contains(strings.ToLower(a.Title), q) || |
| 109 | + strings.Contains(strings.ToLower(a.Content), q) { |
| 110 | + results = append(results, a) |
| 111 | + } |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + // JSON formatında sonuçları döndür |
| 116 | + // Return results in JSON format |
| 117 | + ctx.JSON(200, map[string]interface{}{ |
| 118 | + "count": len(results), // Toplam bulunan sonuç sayısı — Total number of results |
| 119 | + "results": results, // Bulunan makaleler — Found articles |
| 120 | + }) |
| 121 | + }) |
| 122 | + |
| 123 | + // Sunucuyu 8080 portunda çalıştır |
| 124 | + // Run the server on port 8080 |
| 125 | + app.Run(":8080") |
| 126 | +} |
0 commit comments