so://phie

verbal

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

blob: 6ba8fd0574e56abb2b8c65c889490455fcd2025a (1307 bytes)[doc][blame][raw]

1use std::fs;

2use std::fmt;

3use serde::Deserialize;

4

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

6pub struct Server {

7 pub hostname: String,

8 pub port: i32,

9}

10

11impl fmt::Display for Server {

12 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {

13 write!(

14 f,

15 "{}:{}",

16 self.hostname,

17 self.port,

18 )

19 }

20}

21

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

23pub struct Database {

24 pub hostname: String,

25 pub port: i32,

26 pub username: String,

27 pub password: String,

28 pub database: String,

29}

30

31impl fmt::Display for Database {

32 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {

33 write!(

34 f,

35 "postgres://{}:{}@{}:{}/{}?sslmode=disable",

36 self.username,

37 self.password,

38 self.hostname,

39 self.port,

40 self.database,

41 )

42 }

43}

44

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

46pub struct Options {

47 pub origin: String,

48}

49

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

51pub struct Config {

52 pub server: Server,

53 pub database: Database,

54 pub options: Options,

55}

56

57impl Config {

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

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

60 ron::from_str(&raw)

61 }

62}