github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/mobile/primitives.go (about) 1 // This file is part of the go-sberex library. The go-sberex library is 2 // free software: you can redistribute it and/or modify it under the terms 3 // of the GNU Lesser General Public License as published by the Free 4 // Software Foundation, either version 3 of the License, or (at your option) 5 // any later version. 6 // 7 // The go-sberex library is distributed in the hope that it will be useful, 8 // but WITHOUT ANY WARRANTY; without even the implied warranty of 9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 // General Public License <http://www.gnu.org/licenses/> for more details. 11 12 // Contains various wrappers for primitive types. 13 14 package geth 15 16 import ( 17 "errors" 18 "fmt" 19 ) 20 21 // Strings represents s slice of strs. 22 type Strings struct{ strs []string } 23 24 // Size returns the number of strs in the slice. 25 func (s *Strings) Size() int { 26 return len(s.strs) 27 } 28 29 // Get returns the string at the given index from the slice. 30 func (s *Strings) Get(index int) (str string, _ error) { 31 if index < 0 || index >= len(s.strs) { 32 return "", errors.New("index out of bounds") 33 } 34 return s.strs[index], nil 35 } 36 37 // Set sets the string at the given index in the slice. 38 func (s *Strings) Set(index int, str string) error { 39 if index < 0 || index >= len(s.strs) { 40 return errors.New("index out of bounds") 41 } 42 s.strs[index] = str 43 return nil 44 } 45 46 // String implements the Stringer interface. 47 func (s *Strings) String() string { 48 return fmt.Sprintf("%v", s.strs) 49 }