mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-14 16:09:32 +01:00
configure server with json
This commit is contained in:
parent
55d3d6e946
commit
281558072a
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
pkg
|
pkg
|
||||||
bin
|
bin
|
||||||
ergonomadic.db
|
ergonomadic.db
|
||||||
|
ergonomadic.json
|
||||||
|
@ -1,17 +1,27 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
|
||||||
"github.com/jlatt/ergonomadic/irc"
|
"github.com/jlatt/ergonomadic/irc"
|
||||||
|
"log"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
name := flag.String("name", "ergonomadic", "A name for the server")
|
config, err := irc.LoadConfig()
|
||||||
listen := flag.String("listen", ":6667", "interface to listen on")
|
if err != nil {
|
||||||
flag.BoolVar(&irc.DEBUG_NET, "dnet", false, "debug net")
|
log.Fatal(err)
|
||||||
flag.BoolVar(&irc.DEBUG_CLIENT, "dclient", false, "debug client")
|
return
|
||||||
flag.BoolVar(&irc.DEBUG_CHANNEL, "dchannel", false, "debug channel")
|
}
|
||||||
flag.BoolVar(&irc.DEBUG_SERVER, "dserver", false, "debug server")
|
|
||||||
flag.Parse()
|
irc.DEBUG_NET = config.Debug["net"]
|
||||||
irc.NewServer(*name).Listen(*listen)
|
irc.DEBUG_CLIENT = config.Debug["client"]
|
||||||
|
irc.DEBUG_CHANNEL = config.Debug["channel"]
|
||||||
|
irc.DEBUG_SERVER = config.Debug["server"]
|
||||||
|
|
||||||
|
irc.NewServer(config)
|
||||||
|
|
||||||
|
// never finishes
|
||||||
|
wg := sync.WaitGroup{}
|
||||||
|
wg.Add(1)
|
||||||
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
27
irc/config.go
Normal file
27
irc/config.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package irc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
Name string
|
||||||
|
Listen string
|
||||||
|
Password string
|
||||||
|
Debug map[string]bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func LoadConfig() (config *Config, err error) {
|
||||||
|
config = &Config{}
|
||||||
|
|
||||||
|
file, err := os.Open("ergonomadic.json")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
decoder := json.NewDecoder(file)
|
||||||
|
err = decoder.Decode(config)
|
||||||
|
return
|
||||||
|
}
|
@ -19,16 +19,17 @@ type Server struct {
|
|||||||
clients ClientNameMap
|
clients ClientNameMap
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServer(name string) *Server {
|
func NewServer(config *Config) *Server {
|
||||||
commands := make(chan Command)
|
commands := make(chan Command)
|
||||||
server := &Server{
|
server := &Server{
|
||||||
ctime: time.Now(),
|
ctime: time.Now(),
|
||||||
name: name,
|
name: config.Name,
|
||||||
commands: commands,
|
commands: commands,
|
||||||
clients: make(ClientNameMap),
|
clients: make(ClientNameMap),
|
||||||
channels: make(ChannelNameMap),
|
channels: make(ChannelNameMap),
|
||||||
}
|
}
|
||||||
go server.receiveCommands(commands)
|
go server.receiveCommands(commands)
|
||||||
|
go server.listen(config.Listen)
|
||||||
return server
|
return server
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +43,7 @@ func (server *Server) receiveCommands(commands <-chan Command) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Listen(addr string) {
|
func (s *Server) listen(addr string) {
|
||||||
listener, err := net.Listen("tcp", addr)
|
listener, err := net.Listen("tcp", addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Server.Listen: ", err)
|
log.Fatal("Server.Listen: ", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user