so://phie

verbal

A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal

blob: f074e4f4cf156e0d0e8f8f9eebd260ca36a18d69 (1241 bytes)[doc][blame][raw]

1use std::fs;

2use serde::{Deserialize};

3

4#[derive(Debug, Clone, Deserialize)]

5pub struct Server {

6 pub hostname: String,

7 pub port: i32,

8}

9

10impl ToString for Server {

11 fn to_string(&self) -> String {

12 format!(

13 "{}:{}",

14 self.hostname,

15 self.port,

16 )

17 }

18}

19

20#[derive(Debug, Clone, Deserialize)]

21pub struct Database {

22 pub hostname: String,

23 pub port: i32,

24 pub username: String,

25 pub password: String,

26 pub database: String,

27}

28

29impl ToString for Database {

30 fn to_string(&self) -> String {

31 format!(

32 "postgressql://{}:{}@{}:{}/{}?sslmode=disable",

33 self.username,

34 self.password,

35 self.hostname,

36 self.port,

37 self.database,

38 )

39 }

40}

41

42#[derive(Debug, Clone, Deserialize)]

43pub struct Options {

44 pub origin: String,

45 pub api_url: String,

46}

47

48#[derive(Debug, Clone, Deserialize)]

49pub struct Config {

50 pub server: Server,

51 pub database: Database,

52 pub options: Options,

53}

54

55impl Config {

56 pub fn from_file(path: &str) -> Result<Self, ron::Error> {

57 let raw = fs::read_to_string(path).expect("Unable to locate config.ron file!");

58 ron::from_str(&raw)

59 }

60}