-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5718b57
commit d62d1e0
Showing
5 changed files
with
47 additions
and
79 deletions.
There are no files selected for viewing
This file contains 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
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/joho/godotenv" | ||
"path/to/your/project/reCaptchaAPI" // import reCaptchaAPI | ||
) | ||
|
||
func main() { | ||
logDir := filepath.Join("logs", "go") // setting the path for logs | ||
|
||
// Create directory if it does not exist | ||
if err := os.MkdirAll(logDir, os.ModePerm); err != nil { | ||
log.Fatalf("[ERROR] creating log directory: %v", err) | ||
} | ||
|
||
logFile, err := os.OpenFile(filepath.Join(logDir, "recaptcha.log"), os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) | ||
if err != nil { | ||
log.Fatalf("[ERROR] open log directory: %v", err) | ||
} | ||
defer logFile.Close() | ||
|
||
log.SetOutput(logFile) // redirect logs to a file | ||
|
||
if err := godotenv.Load(); err != nil { | ||
log.Fatalf("[ERROR] No .env file found") | ||
} else { | ||
log.Println("[SUCCESS] .env file found") | ||
} | ||
|
||
http.HandleFunc("/validate-recaptcha", reCaptchaAPI.RecaptchaHandler) // use the handler from the package | ||
log.Println("[SUCCESS] Starting server on :8080...") | ||
if err := http.ListenAndServe(":8080", nil); err != nil { | ||
log.Fatalf("[ERROR] Error starting server: %v", err) | ||
} | ||
} |
This file contains 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