This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Simple web server in Go | |
| // All go applications start with package main, which defines a standalone executable program | |
| package main | |
| // Import necessary packages | |
| import ( | |
| "log" // Package for logging | |
| "net/http" // Package for HTTP client and server implementations | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 23:07:57.558: [macOS] Permission for audio device access granted. | |
| 23:07:57.560: [macOS] Permission for video device access granted. | |
| 23:07:57.560: [macOS] Permission for input monitoring denied. | |
| 23:07:57.563: [macOS] Permission for screen capture granted. | |
| 23:07:57.564: CPU Name: Apple M4 | |
| 23:07:57.564: Physical Cores: 10, Logical Cores: 10 | |
| 23:07:57.564: Physical Memory: 16384MB Total | |
| 23:07:57.564: Model Identifier: Mac16,1 | |
| 23:07:57.564: OS Name: macOS | |
| 23:07:57.564: OS Version: Version 15.6.1 (Build 24G90) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func Insert(w http.ResponseWriter, r *http.Request) { | |
| db := utils.DbConn() | |
| //If it's a post request, assign a variable to the value returned in each field of the New page. | |
| if r.Method == "POST" { | |
| username := r.FormValue("username") | |
| password := r.FormValue("password") | |
| city := r.FormValue("city") | |
| email := r.FormValue("email") | |
| // encrypt password |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "github.com/eomolo/user_auth/myapp/routes" | |
| _ "github.com/lib/pq" | |
| "log" | |
| "net/http" | |
| ) | |
| func main() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package routes | |
| import ( | |
| "github.com/eomolo/user_auth/myapp/controllers" | |
| "github.com/gorilla/mux" | |
| ) | |
| func Handlers() *mux.Router { | |
| r := mux.NewRouter().StrictSlash(true) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package utils | |
| import ( | |
| "database/sql" | |
| "fmt" | |
| "github.com/joho/godotenv" | |
| "log" | |
| "os" | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package controllers | |
| import ( | |
| "github.com/eomolo/user_auth/myapp/models" | |
| "github.com/eomolo/user_auth/myapp/utils" | |
| _ "github.com/lib/pq" | |
| "log" | |
| "net/http" | |
| "text/template" | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package models | |
| // define a user model | |
| type User struct { | |
| Id int | |
| Username string | |
| City string | |
| Email string | |
| Password string | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "database/sql" | |
| "fmt" | |
| "github.com/joho/godotenv" | |
| _ "github.com/lib/pq" | |
| "log" | |
| "net/http" | |
| "os" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func Delete(w http.ResponseWriter, r *http.Request) { | |
| db := dbConn() | |
| usr := r.URL.Query().Get("id") | |
| delForm, err := db.Prepare(`DELETE FROM public."users" WHERE user_id=$1`) | |
| if err != nil { | |
| panic(err.Error()) | |
| } | |
| delForm.Exec(usr) | |
| log.Println("DELETE") | |
| defer db.Close() |
NewerOlder