GetString returns value stored in the environment, casted to string. If value does not exist, or is not string, reports failure and returns empty string. Example: value := env.GetString("key")
(key string)
| 315 | // |
| 316 | // value := env.GetString("key") |
| 317 | func (e *Environment) GetString(key string) string { |
| 318 | opChain := e.chain.enter("GetString(%q)", key) |
| 319 | defer opChain.leave() |
| 320 | |
| 321 | e.mu.RLock() |
| 322 | defer e.mu.RUnlock() |
| 323 | |
| 324 | value, ok := envValue(opChain, e.data, key) |
| 325 | if !ok { |
| 326 | return "" |
| 327 | } |
| 328 | |
| 329 | casted, ok := value.(string) |
| 330 | if !ok { |
| 331 | opChain.fail(AssertionFailure{ |
| 332 | Type: AssertType, |
| 333 | Actual: &AssertionValue{value}, |
| 334 | Errors: []error{ |
| 335 | errors.New("expected: string value"), |
| 336 | }, |
| 337 | }) |
| 338 | return "" |
| 339 | } |
| 340 | |
| 341 | return casted |
| 342 | } |
| 343 | |
| 344 | // GetBytes returns value stored in the environment, casted to []byte. |
| 345 | // |