Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/master.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
on: push
name: Master action
jobs:
checks:
name: run
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master

- name: run
uses: cedrickring/golang-action@1.6.0
4 changes: 2 additions & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ func ListenAndServe(addr string) error {
}

func (s *Server) handleConn(conn net.Conn) {
defer conn.Close()
defer func() {
if r := recover(); r != nil {
log.Println("panic:", r)
}
}()
}()
defer conn.Close()
for {
buf := make([]byte, 1024)
n, err := conn.Read(buf)
Expand Down
10 changes: 5 additions & 5 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type entry struct {
// in the memory and removed once accessed, in case the key expired.
type Store struct {
values map[string]entry
mu sync.RWMutex
mu sync.Mutex
}

// New creates a new instance of Store.
Expand All @@ -29,9 +29,9 @@ func New() *Store {

// Get returns the actual value for the given key and value indicating the existence.
func (s *Store) Get(key string) (string, bool) {
s.mu.RLock()
s.mu.Lock()
defer s.mu.Unlock()
v, ok := s.values[key]
s.mu.RUnlock()
if ok && !v.ts.IsZero() {
if v.ts.Before(time.Now()) {
delete(s.values, key)
Expand Down Expand Up @@ -62,7 +62,7 @@ func (s *Store) SetWithExpirity(key, value string, expirity time.Duration) {

// Len returns length of the store.
func (s *Store) Len() int {
s.mu.RLock()
defer s.mu.RUnlock()
s.mu.Lock()
defer s.mu.Lock()
return len(s.values)
}