implemented HTTP 1.0/1.1 server

This commit is contained in:
Altair-sh
2026-11-01 20:43:08 +01:00
parent 2de1f038c7
commit e0cf8a12a9
13 changed files with 956 additions and 68 deletions
+4 -24
View File
@@ -1,23 +1,21 @@
package server
import (
"encoding"
"errors"
"fmt"
"io/fs"
"net"
"os"
"github.com/BurntSushi/toml"
)
// TODO: add example config file
type Config struct {
Port uint16 `toml:"port"`
Ip IP `toml:"ip"`
Addr string `toml:"address"`
}
func ReadConfig(path string) (*Config, error) {
var config = new(Config)
var config = DefaultConfig()
tomlMeta, err := toml.DecodeFile(path, config)
if err != nil {
return nil, err
@@ -33,8 +31,7 @@ func ReadConfig(path string) (*Config, error) {
func DefaultConfig() *Config {
return &Config{
Port: 8080,
Ip: IP{net.IPv4(127, 0, 0, 1)},
Addr: "127.0.0.1:8080",
}
}
@@ -62,20 +59,3 @@ func WriteConfig(config *Config, path string) (err error) {
enc.Indent = " " // 4
return enc.Encode(config)
}
type IP struct {
net.IP
}
var _ encoding.TextUnmarshaler = (*IP)(nil)
var _ encoding.TextMarshaler = IP{}
func (a *IP) UnmarshalText(text []byte) error {
s := string(text)
ip := net.ParseIP(s)
if ip == nil {
return errors.New("can't parse '" + s + "' as IP address")
}
a.IP = ip
return nil
}