Skip to content

Commit 9497476

Browse files
author
Coderian
authored
Add files via upload
1 parent ee75189 commit 9497476

File tree

10 files changed

+447
-0
lines changed

10 files changed

+447
-0
lines changed

examples/basic/main.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package main
2+
3+
import "github.com/coderianx/flint"
4+
5+
func main() {
6+
app := flint.NewServer()
7+
8+
app.Handle("/", func(ctx *flint.Context) {
9+
ctx.String(200, "Hello Flint Familyyy")
10+
})
11+
12+
app.Run(":8080")
13+
}

examples/basic/useragent/main.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/coderianx/flint"
7+
)
8+
9+
func main() {
10+
app := flint.NewServer()
11+
12+
app.Handle("/", func(ctx *flint.Context) {
13+
useragent := ctx.UserAgent()
14+
fmt.Println("UserAgent: ", useragent)
15+
ctx.Stringf(200, "Your Useragent: %s", useragent)
16+
})
17+
18+
app.Run()
19+
}

examples/examples.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
**In this folder, you’ll find a collection of usage examples and small-scale real-world applications built with the Flint Framework. Each example is designed to demonstrate different features, architectural patterns, and best practices for building web applications using Flint.**
2+
3+
**Whether you’re just getting started or exploring more advanced capabilities, these examples cover a range of scenarios — from basic “Hello World” setups to more complex mini-projects such as authentication systems, RESTful APIs, and template rendering.**
4+
5+
**You can explore the code, run each project locally, and adapt the patterns to your own applications. The goal of this folder is to provide a hands-on learning resource, making it easier to understand Flint’s core concepts and how they fit into real development workflows.**

examples/register_app/README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Register App / Kayıt Uygulaması
2+
3+
Bu dosya, **Flint Framework** kullanarak basit bir kullanıcı kayıt formu örneğini hem Türkçe hem İngilizce olarak açıklar.
4+
This file explains a simple user registration form example using **Flint Framework** in both Turkish and English.
5+
6+
---
7+
8+
## 📂 Project Structure / Proje Yapısı
9+
```
10+
examples/register_app/
11+
├── main.go
12+
├── index.html
13+
└── README.md
14+
```
15+
- **main.go** → Server code / Sunucu kodu
16+
- **index.html** → Basic HTML registration form / Basit HTML kayıt formu
17+
- **README.md** → This description file / Bu açıklama dosyası
18+
19+
---
20+
21+
## 🚀 Running / Çalıştırma
22+
23+
**English**
24+
1. Install Flint framework:
25+
```bash
26+
go get github.com/coderianx/flint
27+
```
28+
2. Run the example:
29+
```bash
30+
go run main.go
31+
```
32+
3. Open in browser:
33+
```
34+
http://localhost:8080
35+
````
36+
37+
**Türkçe**
38+
1. Flint framework'ü yükle:
39+
```bash
40+
go get github.com/coderianx/flint
41+
```
42+
2. Örneği çalıştır:
43+
```bash
44+
go run main.go
45+
```
46+
3. Tarayıcıdan aç:
47+
```
48+
http://localhost:8080
49+
```
50+
51+
---
52+
53+
## 📋 Usage / Kullanım
54+
55+
**English**
56+
1. Enter a username and password in the form.
57+
2. Click the **Submit** button.
58+
3. The server will capture the submitted data and respond with a welcome message.
59+
60+
**Türkçe**
61+
1. Açılan formda kullanıcı adı ve şifre girin.
62+
2. **Gönder** butonuna basın.
63+
3. Sunucu, girilen bilgileri alır ve hoş geldin mesajı döner.
64+
65+
---
66+
67+
## 📌 Notes / Notlar
68+
69+
**English**
70+
- This example demonstrates how Flint’s **FormData()** method works.
71+
- In real-world applications, passwords should be **hashed** and stored in a database.
72+
73+
**Türkçe**
74+
- Bu örnek, Flint’in **FormData()** metodunu nasıl kullandığını gösterir.
75+
- Gerçek projelerde şifreler **hashlenmeli** ve veritabanına kaydedilmelidir.

examples/register_app/index.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Flint Register App</title>
7+
</head>
8+
<body>
9+
<h1>Flint</h1>
10+
<h2>Register app</h2>
11+
<form action="/" method="POST">
12+
<input type="text" name="username" placeholder="Enter Username" required>
13+
<br><br>
14+
<input type="text" name="password" placeholder="Enter Password" required>
15+
<br><br>
16+
<button type="submit">Register</button>
17+
</form>
18+
</body>
19+
</html>

examples/register_app/main.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/coderianx/flint"
7+
)
8+
9+
func main() {
10+
app := flint.NewServer()
11+
12+
app.Handle("/", func(ctx *flint.Context) {
13+
if ctx.Get() {
14+
ctx.File("./examples/register_app/index.html")
15+
return
16+
}
17+
if ctx.Post() {
18+
username := ctx.FormData("username")
19+
password := ctx.FormData("password")
20+
ctx.Stringf(200, "Hoşgeldin %s", username)
21+
fmt.Println(username, ":", password)
22+
}
23+
})
24+
25+
app.Run(":3000")
26+
}

examples/search/index.html

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<!doctype html>
2+
<html lang="tr">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Arama / Search</title>
6+
<style>
7+
body { font-family: Arial, sans-serif; padding: 20px; }
8+
input[type="search"] { width: 60%; padding: 8px; }
9+
button { padding: 8px 12px; }
10+
.card { border: 1px solid #ddd; padding: 12px; margin: 8px 0; border-radius: 6px; }
11+
.meta { color: #666; font-size: 0.9rem; }
12+
</style>
13+
</head>
14+
<body>
15+
<h1>Arama / Search</h1>
16+
17+
<form id="searchForm">
18+
<input type="search" id="searchInput" name="q" placeholder="Ara... / Search...">
19+
<button type="submit">Ara</button>
20+
</form>
21+
22+
<div id="results"></div>
23+
24+
<script>
25+
// Sayfa yüklenince çalış
26+
document.addEventListener("DOMContentLoaded", () => {
27+
const params = new URLSearchParams(window.location.search);
28+
const q = params.get("q") || "";
29+
document.getElementById("searchInput").value = q;
30+
31+
if (q) {
32+
fetch(`/api/search?q=${encodeURIComponent(q)}`)
33+
.then(res => res.json())
34+
.then(data => {
35+
const resultsDiv = document.getElementById("results");
36+
resultsDiv.innerHTML = `<p class="meta">Aranan: <strong>${q}</strong> — Bulunan: ${data.count}</p>`;
37+
if (data.results.length > 0) {
38+
data.results.forEach(item => {
39+
const div = document.createElement("div");
40+
div.className = "card";
41+
div.innerHTML = `<h3>${item.title}</h3><p>${item.content}</p>`;
42+
resultsDiv.appendChild(div);
43+
});
44+
} else {
45+
resultsDiv.innerHTML += `<p>Sonuç bulunamadı / No results found.</p>`;
46+
}
47+
});
48+
}
49+
});
50+
51+
// Form submit olduğunda URL'yi güncelle
52+
document.getElementById("searchForm").addEventListener("submit", e => {
53+
e.preventDefault();
54+
const q = document.getElementById("searchInput").value;
55+
window.location.href = `/?q=${encodeURIComponent(q)}`;
56+
});
57+
</script>
58+
</body>
59+
</html>

examples/search/main.go

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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+
}

examples/simple_restapi/main.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package main
2+
3+
import "github.com/coderianx/flint"
4+
5+
// TR: Basit bir örnek REST API
6+
// Bu örnekte /users adresine gittiğinizde JSON formatında kullanıcı listesi döndürülür.
7+
//
8+
// EN: Simple example REST API
9+
// In this example, visiting /users will return a JSON-formatted list of users.
10+
func main() {
11+
app := flint.NewServer()
12+
13+
// TR: JSON olarak döndürülecek kullanıcı listesi
14+
// EN: User list to be returned as JSON
15+
users := []map[string]interface{}{
16+
{"id": 1, "name": "Flint"},
17+
{"id": 2, "name": "Framework"},
18+
}
19+
20+
// TR: /users isteği geldiğinde kullanıcı listesini JSON olarak döndür
21+
// EN: When /users is requested, return the user list as JSON
22+
app.Handle("/users", func(ctx *flint.Context) {
23+
ctx.JSON(200, users)
24+
})
25+
26+
// TR: Sunucuyu 8080 portunda başlat
27+
// EN: Start the server on port 8080
28+
app.Run(":8080")
29+
}

0 commit comments

Comments
 (0)