Name all storage interface params, return slices of pointers

This commit is contained in:
Ken-Håvard Lieng 2018-06-01 04:16:38 +02:00
parent 09248edd59
commit e0200a2b2a
11 changed files with 65 additions and 52 deletions

View file

@ -24,7 +24,7 @@ type connectDefaults struct {
type indexData struct {
Defaults connectDefaults
Servers []Server
Channels []storage.Channel
Channels []*storage.Channel
// Users in the selected channel
Users *Userlist
@ -116,7 +116,7 @@ func (d *indexData) addUsersAndMessages(server, channel string, state *State) {
}
}
func isInChannel(channels []storage.Channel, server, channel string) bool {
func isInChannel(channels []*storage.Channel, server, channel string) bool {
if channel != "" {
for _, ch := range channels {
if server == ch.Server && channel == ch.Name {

View file

@ -74,16 +74,24 @@ func easyjson7e607aefDecodeGithubComKhliengDispatchServer(in *jlexer.Lexer, out
in.Delim('[')
if out.Channels == nil {
if !in.IsDelim(']') {
out.Channels = make([]storage.Channel, 0, 1)
out.Channels = make([]*storage.Channel, 0, 8)
} else {
out.Channels = []storage.Channel{}
out.Channels = []*storage.Channel{}
}
} else {
out.Channels = (out.Channels)[:0]
}
for !in.IsDelim(']') {
var v2 storage.Channel
easyjson7e607aefDecodeGithubComKhliengDispatchStorage(in, &v2)
var v2 *storage.Channel
if in.IsNull() {
in.Skip()
v2 = nil
} else {
if v2 == nil {
v2 = new(storage.Channel)
}
easyjson7e607aefDecodeGithubComKhliengDispatchStorage(in, &*v2)
}
out.Channels = append(out.Channels, v2)
in.WantComma()
}
@ -170,7 +178,11 @@ func easyjson7e607aefEncodeGithubComKhliengDispatchServer(out *jwriter.Writer, i
if v5 > 0 {
out.RawByte(',')
}
easyjson7e607aefEncodeGithubComKhliengDispatchStorage(out, v6)
if v6 == nil {
out.RawString("null")
} else {
easyjson7e607aefEncodeGithubComKhliengDispatchStorage(out, *v6)
}
}
out.RawByte(']')
}

View file

@ -20,7 +20,7 @@ type WSResponse struct {
}
type Server struct {
storage.Server
*storage.Server
Status ConnectionUpdate
}

View file

@ -766,6 +766,7 @@ func easyjson42239ddeDecodeGithubComKhliengDispatchServer7(in *jlexer.Lexer, out
in.Skip()
return
}
out.Server = new(storage.Server)
in.Delim('{')
for !in.IsDelim('}') {
key := in.UnsafeString()

View file

@ -59,8 +59,8 @@ func (d *Dispatch) loadUsers() {
log.Printf("Loading %d user(s)", len(users))
for i := range users {
go d.loadUser(&users[i])
for _, user := range users {
go d.loadUser(user)
}
}
@ -92,7 +92,7 @@ func (d *Dispatch) loadUser(user *storage.User) {
}
for _, server := range servers {
i := connectIRC(&server, state)
i := connectIRC(server, state)
var joining []string
for _, channel := range channels {

View file

@ -247,8 +247,8 @@ func newStateStore(sessionStore storage.SessionStore) *stateStore {
for _, session := range sessions {
if !session.Expired() {
session.Init()
store.sessions[session.Key()] = &session
go deleteSessionWhenExpired(&session, store)
store.sessions[session.Key()] = session
go deleteSessionWhenExpired(session, store)
} else {
go sessionStore.DeleteSession(session.Key())
}

View file

@ -90,9 +90,9 @@ func (h *wsHandler) connect(b []byte) {
if _, ok := h.state.getIRC(data.Host); !ok {
log.Println(h.addr, "[IRC] Add server", data.Host)
connectIRC(&data.Server, h.state)
connectIRC(data.Server, h.state)
go h.state.user.AddServer(&data.Server)
go h.state.user.AddServer(data.Server)
} else {
log.Println(h.addr, "[IRC]", data.Host, "already added")
}