github.com/zhongdalu/gf@v1.0.0/g/os/gcmd/gcmd_value.go (about) 1 // Copyright 2017 gf Author(https://github.com/zhongdalu/gf). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/zhongdalu/gf. 6 // 7 8 package gcmd 9 10 import "github.com/zhongdalu/gf/g/container/gvar" 11 12 // GetAll returns all values as a slice of string. 13 func (c *gCmdValue) GetAll() []string { 14 return c.values 15 } 16 17 // Get returns value by index <index> as string, 18 // if value does not exist, then returns <def>. 19 func (c *gCmdValue) Get(index int, def ...string) string { 20 if index < len(c.values) { 21 return c.values[index] 22 } else if len(def) > 0 { 23 return def[0] 24 } 25 return "" 26 } 27 28 // GetVar returns value by index <index> as *gvar.Var object, 29 // if value does not exist, then returns <def> as its default value. 30 func (c *gCmdValue) GetVar(index int, def ...string) *gvar.Var { 31 return gvar.New(c.Get(index, def...), true) 32 }