Something went wrong. Try again.
Random IRC. Totally useless, totally unsafe, totally random™. My entry project to the go language
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071package server
import ( "net"
"github.com/google/uuid")
type UserRole = int
const ( UserRoleDefault UserRole = iota UserRoleModerator UserRoleAdmin)
type Message struct { id uuid.UUID content []string writer *User}
type Channel struct { id uuid.UUID name string writePermission UserRole
messageHistory []Message}
func NewChannelID(id uuid.UUID, name string, perm UserRole) Channel { return Channel{ id: id, name: name, writePermission: perm, }}
func NewChannel(name string, perm UserRole) Channel { return NewChannelID(uuid.New(), name, perm)}
type User struct { id uuid.UUID name string role UserRole
conn net.Conn // nil if offline}
type Server struct { conn net.Conn channels []*Channel users []*User}
func NewServer() Server { return Server{ channels: []*Channel{}, users: []*User{}, }}
func (s *Server) AddChannel(channel *Channel) { s.channels = append(s.channels, channel)}
func (s *Server) AddUser(user *User) { s.users = append(s.users, user)}