Browse Source

Human readable variables

Volodymyr Tkach 2 years ago
parent
commit
becd6c64d5
4 changed files with 19 additions and 19 deletions
  1. 3 3
      session/bool.go
  2. 3 3
      session/int.go
  3. 10 10
      session/session.go
  4. 3 3
      session/string.go

+ 3 - 3
session/bool.go

@@ -1,7 +1,7 @@
 package session
 
 func (s *Session) IsSetBool(name string) bool {
-	if _, ok := s.v.Bool[name]; ok {
+	if _, ok := s.varlist.Bool[name]; ok {
 		return true
 	} else {
 		return false
@@ -9,7 +9,7 @@ func (s *Session) IsSetBool(name string) bool {
 }
 
 func (s *Session) GetBool(name string, def bool) bool {
-	if v, ok := s.v.Bool[name]; ok {
+	if v, ok := s.varlist.Bool[name]; ok {
 		return v
 	} else {
 		return def
@@ -18,7 +18,7 @@ func (s *Session) GetBool(name string, def bool) bool {
 
 func (s *Session) SetBool(name string, value bool) {
 	isset := s.IsSetBool(name)
-	s.v.Bool[name] = value
+	s.varlist.Bool[name] = value
 	if isset || value {
 		s.c = true
 	}

+ 3 - 3
session/int.go

@@ -1,7 +1,7 @@
 package session
 
 func (s *Session) IsSetInt(name string) bool {
-	if _, ok := s.v.Int[name]; ok {
+	if _, ok := s.varlist.Int[name]; ok {
 		return true
 	} else {
 		return false
@@ -9,7 +9,7 @@ func (s *Session) IsSetInt(name string) bool {
 }
 
 func (s *Session) GetInt(name string, def int) int {
-	if v, ok := s.v.Int[name]; ok {
+	if v, ok := s.varlist.Int[name]; ok {
 		return v
 	} else {
 		return def
@@ -18,7 +18,7 @@ func (s *Session) GetInt(name string, def int) int {
 
 func (s *Session) SetInt(name string, value int) {
 	isset := s.IsSetInt(name)
-	s.v.Int[name] = value
+	s.varlist.Int[name] = value
 	if isset || value != 0 {
 		s.c = true
 	}

+ 10 - 10
session/session.go

@@ -18,16 +18,16 @@ type vars struct {
 }
 
 type Session struct {
-	w      http.ResponseWriter
-	r      *http.Request
-	tmpdir string
-	v      *vars
-	c      bool
-	i      string
+	w       http.ResponseWriter
+	r       *http.Request
+	tmpdir  string
+	varlist *vars
+	c       bool
+	i       string
 }
 
 func New(w http.ResponseWriter, r *http.Request, tmpdir string) *Session {
-	sess := Session{w: w, r: r, tmpdir: tmpdir, v: &vars{}, c: false, i: ""}
+	sess := Session{w: w, r: r, tmpdir: tmpdir, varlist: &vars{}, c: false, i: ""}
 
 	cookie, err := r.Cookie("session")
 	if err == nil && len(cookie.Value) == 40 {
@@ -38,7 +38,7 @@ func New(w http.ResponseWriter, r *http.Request, tmpdir string) *Session {
 		if err == nil {
 			defer f.Close()
 			dec := json.NewDecoder(f)
-			err = dec.Decode(&sess.v)
+			err = dec.Decode(&sess.varlist)
 			if err == nil {
 				return &sess
 			}
@@ -75,7 +75,7 @@ func New(w http.ResponseWriter, r *http.Request, tmpdir string) *Session {
 	}
 
 	// Init empty
-	sess.v = &vars{
+	sess.varlist = &vars{
 		Bool:   map[string]bool{},
 		Int:    map[string]int{},
 		String: map[string]string{},
@@ -89,7 +89,7 @@ func (s *Session) Close() bool {
 		return false
 	}
 
-	r, err := json.Marshal(s.v)
+	r, err := json.Marshal(s.varlist)
 	if err == nil {
 		f, err := os.Create(strings.Join([]string{s.tmpdir, s.i}, string(os.PathSeparator)))
 		if err == nil {

+ 3 - 3
session/string.go

@@ -1,7 +1,7 @@
 package session
 
 func (s *Session) IsSetString(name string) bool {
-	if _, ok := s.v.String[name]; ok {
+	if _, ok := s.varlist.String[name]; ok {
 		return true
 	} else {
 		return false
@@ -9,7 +9,7 @@ func (s *Session) IsSetString(name string) bool {
 }
 
 func (s *Session) GetString(name string, def string) string {
-	if v, ok := s.v.String[name]; ok {
+	if v, ok := s.varlist.String[name]; ok {
 		return v
 	} else {
 		return def
@@ -18,7 +18,7 @@ func (s *Session) GetString(name string, def string) string {
 
 func (s *Session) SetString(name string, value string) {
 	isset := s.IsSetString(name)
-	s.v.String[name] = value
+	s.varlist.String[name] = value
 	if isset || value != "" {
 		s.c = true
 	}