Implement UDP socket server and add package installation check utility
This commit is contained in:
36
cmd/httpsocket/main.go
Normal file
36
cmd/httpsocket/main.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"packets/configs"
|
||||
"packets/internal/consts"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type ConfigTOML struct {
|
||||
Config struct {
|
||||
DefaultHttpPort int `toml:"httpPort"`
|
||||
DefaultCacheDir string `toml:"cacheDir"`
|
||||
} `toml:"Config"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
cfg, err := configs.GetConfigTOML()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
pid := os.Getpid()
|
||||
if err := os.WriteFile(filepath.Join(consts.DefaultLinux_d, "http.pid"), []byte(fmt.Sprint(pid)), 0664); err != nil {
|
||||
fmt.Println("error saving subprocess pid", err)
|
||||
}
|
||||
|
||||
fs := http.FileServer(http.Dir(cfg.Config.Cache_d))
|
||||
http.Handle("/", fs)
|
||||
|
||||
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", cfg.Config.HttpPort), nil))
|
||||
}
|
||||
Reference in New Issue
Block a user