/// Generate sc_endpoint by combining all config elements. Returns error on failure.
Generate sc_endpoint by combining all config elements. Returns error on failure.
Generate sc_endpoint by combining all config elements . Returns error on failure .
fn make_sc_endpoint(
        cli_cfg: &SpuOpt,
        file_cfg: &Option<SpuConfigFile>,
    ) -> Result<ServerAddress, IoError> {
        // 1) check cli and convert to server address
        let mut sc_ep = server_str_to_server_addr(&cli_cfg.sc_server)?;
        // 2) environment variable (optional field, ignore errors)
        if sc_ep.is_none() {
            debug!("no sc endpoint is supplied. checking env");
            if let Ok(host) = env::var(FLV_SC_PRIVATE_HOST) {
                debug!("found sc addr from env var: {}",host);
                if let Ok(port_str) = env::var(FLV_SC_PRIVATE_PORT) {
                    let port: u16 = port_str.parse().map_err(|err| {
                        IoError::new(
                            ErrorKind::InvalidInput,
                            format!("invalid env port: {}", err),
                        )
                    })?;
                    return Ok(ServerAddress { host, port });
                } else {
                    debug!("no port supplied with env var, using default port: {}",SC_PRIVATE_PORT);
                    return Ok(ServerAddress { host, port: SC_PRIVATE_PORT})
                }
            } else {
                debug!("no sc endpoint from env var");
            }
        }
        // 3) config file
        if sc_ep.is_none() && file_cfg.is_some() {
            debug!("try reading sc from file");
            sc_ep = file_cfg.as_ref().unwrap().controller_endpoint();
        }
        // 4) use default
        match sc_ep {
            Some(addr) => Ok(addr),
            None => {
                debug!("no sc endpoint from any config source, default to localhost");
                let host = SC_HOSTNAME.to_owned();
                let port = SC_PRIVATE_PORT;
                Ok(ServerAddress { host, port })
            }
        }
    }
fn make_sc_endpoint ( cli_cfg : & SpuOpt , file_cfg : & Option < SpuConfigFile > , ) -> Result < ServerAddress , IoError > { // 1) check cli and convert to server address let mut sc_ep = server_str_to_server_addr ( & cli_cfg . sc_server ) ? ; // 2) environment variable (optional field, ignore errors) if sc_ep . is_none ( ) { debug ! ( " " ) ; if let Ok ( host ) = env :: var ( FLV_SC_PRIVATE_HOST ) { debug ! ( " " host ) ; if let Ok ( port_str ) = env :: var ( FLV_SC_PRIVATE_PORT ) { let port : u16 = port_str . parse ( ) . map_err ( | err | { IoError :: new ( ErrorKind :: InvalidInput , format ! ( " " err ) , ) } ) ? ; return Ok ( ServerAddress { host , port } ) ; } else { debug ! ( " " SC_PRIVATE_PORT ) ; return Ok ( ServerAddress { host , port : SC_PRIVATE_PORT } ) } } else { debug ! ( " " ) ; } } // 3) config file if sc_ep . is_none ( ) && file_cfg . is_some ( ) { debug ! ( " " ) ; sc_ep = file_cfg . as_ref ( ) . unwrap ( ) . controller_endpoint ( ) ; } // 4) use default match sc_ep { Some ( addr ) => Ok ( addr ) , None => { debug ! ( " " ) ; let host = SC_HOSTNAME . to_owned ( ) ; let port = SC_PRIVATE_PORT ; Ok ( ServerAddress { host , port } ) } } }
Generate sc_endpoint by combining all config elements.
Generate sc_endpoint by combining all config elements .
cli_cfg
&SpuOpt
file_cfg
&Option<SpuConfigFile>