2023-08-21 12:19:31 +05:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
2023-08-21 12:39:38 +05:00
|
|
|
"net/http"
|
2023-08-21 12:19:31 +05:00
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
func NewServer(port string) (error) {
|
2023-08-21 12:39:38 +05:00
|
|
|
server := http.NewServeMux()
|
|
|
|
server_setup(server)
|
|
|
|
if err := http.ListenAndServe(":" + port, server); err != nil {
|
2023-08-21 12:19:31 +05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-08-21 12:39:38 +05:00
|
|
|
func server_setup(server *http.ServeMux) {
|
|
|
|
server.HandleFunc("/", test)
|
2023-08-21 12:19:31 +05:00
|
|
|
}
|
|
|
|
|
2023-08-21 12:39:38 +05:00
|
|
|
func test(w http.ResponseWriter, r *http.Request) {
|
|
|
|
test_buf := make([]byte, 32)
|
|
|
|
copy(test_buf, "test\ntest")
|
|
|
|
if _, err := w.Write(test_buf); err != nil {
|
|
|
|
fmt.Println(err)
|
2023-08-21 12:19:31 +05:00
|
|
|
}
|
|
|
|
}
|