mirror of
https://github.com/ION606/MailPocket.git
synced 2026-05-14 22:06:55 +00:00
initial code commit
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
module sqlite-server
|
||||
|
||||
go 1.23.6
|
||||
|
||||
require (
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/ncruces/go-strftime v0.1.9 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
golang.org/x/sys v0.22.0 // indirect
|
||||
modernc.org/libc v1.55.3 // indirect
|
||||
modernc.org/mathutil v1.6.0 // indirect
|
||||
modernc.org/memory v1.8.0 // indirect
|
||||
modernc.org/sqlite v1.34.5 // indirect
|
||||
)
|
||||
@@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
_ "modernc.org/sqlite"
|
||||
)
|
||||
|
||||
const PORT = ":3000"
|
||||
|
||||
func main() {
|
||||
db, _ := sql.Open("sqlite", "emails.db")
|
||||
db.Exec(`CREATE TABLE IF NOT EXISTS emails (
|
||||
email TEXT PRIMARY KEY,
|
||||
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)`)
|
||||
|
||||
http.HandleFunc("/submit", func(w http.ResponseWriter, r *http.Request) {
|
||||
email := strings.TrimSpace(r.FormValue("email"))
|
||||
if email == "" {
|
||||
http.Error(w, "Email required", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
_, err := db.Exec(`INSERT OR IGNORE INTO emails(email) VALUES (?)`, email)
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
if err != nil {
|
||||
json.NewEncoder(w).Encode(map[string]string{"error": "storage failed"})
|
||||
return
|
||||
}
|
||||
json.NewEncoder(w).Encode(map[string]string{"message": "data received"})
|
||||
})
|
||||
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte("SQLite Write Server is running"))
|
||||
})
|
||||
|
||||
http.ListenAndServe(PORT, nil)
|
||||
}
|
||||
Reference in New Issue
Block a user