add new file go/l16.go for serve html file from env path
This commit is contained in:
parent
694ed7d17a
commit
f902723e2c
2 changed files with 30 additions and 0 deletions
30
go/l16.go
Normal file
30
go/l16.go
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"net/http"
|
||||||
|
"log"
|
||||||
|
"github.com/joho/godotenv"
|
||||||
|
)
|
||||||
|
|
||||||
|
func handler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
err := godotenv.Load()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("%v\n", err)
|
||||||
|
}
|
||||||
|
PathFile := os.Getenv("html_file_for_l16.go") // Enter the file path for the html_file_for_l16.go variable into the env file
|
||||||
|
html, err := os.ReadFile(PathFile)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("%v\n", err)
|
||||||
|
}
|
||||||
|
fmt.Fprintf(w, string(html))
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
http.HandleFunc("/", handler)
|
||||||
|
err := http.ListenAndServe(":2345", nil)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("%v\n", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
go/output/l16
Executable file
BIN
go/output/l16
Executable file
Binary file not shown.
Loading…
Reference in a new issue