Service retrieves and sets a currently running service registered of a specific type.
(service interface{})
| 503 | |
| 504 | // Service retrieves and sets a currently running service registered of a specific type. |
| 505 | func (n *Node) Service(service interface{}) error { |
| 506 | n.lock.RLock() |
| 507 | defer n.lock.RUnlock() |
| 508 | |
| 509 | // Short circuit if the node's not running |
| 510 | if n.server == nil { |
| 511 | return ErrNodeStopped |
| 512 | } |
| 513 | // Otherwise try to find the service to return |
| 514 | element := reflect.ValueOf(service).Elem() |
| 515 | if running, ok := n.services[element.Type()]; ok { |
| 516 | element.Set(reflect.ValueOf(running)) |
| 517 | return nil |
| 518 | } |
| 519 | return ErrServiceUnknown |
| 520 | } |
| 521 | |
| 522 | // creates the directory and adds the lock |
| 523 | func (n *Node) openDataDir() error { |