forked from vieter-v/vieter
Compare commits
3 Commits
0233b8559d
...
ce6a5db29b
| Author | SHA1 | Date |
|---|---|---|
|
|
ce6a5db29b | |
|
|
e7a0aa4c90 | |
|
|
6e6249396a |
|
|
@ -4,6 +4,7 @@ import docker
|
||||||
import encoding.base64
|
import encoding.base64
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
|
import db
|
||||||
import strings
|
import strings
|
||||||
import util
|
import util
|
||||||
import models { GitRepo }
|
import models { GitRepo }
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import cron.expression { CronExpression, parse_expression }
|
||||||
import math
|
import math
|
||||||
import build
|
import build
|
||||||
import docker
|
import docker
|
||||||
|
import db
|
||||||
import os
|
import os
|
||||||
import client
|
import client
|
||||||
import models { GitRepo }
|
import models { GitRepo }
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
module models
|
module models
|
||||||
|
|
||||||
// from_params<T> creates a new instance of T from the given map by parsing all
|
|
||||||
// of its fields from the map.
|
|
||||||
pub fn from_params<T>(params map[string]string) ?T {
|
pub fn from_params<T>(params map[string]string) ?T {
|
||||||
mut o := T{}
|
mut o := T{}
|
||||||
|
|
||||||
|
|
@ -10,8 +8,6 @@ pub fn from_params<T>(params map[string]string) ?T {
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
// patch_from_params<T> updates the given T object with the params defined in
|
|
||||||
// the map.
|
|
||||||
pub fn patch_from_params<T>(mut o T, params map[string]string) ? {
|
pub fn patch_from_params<T>(mut o T, params map[string]string) ? {
|
||||||
$for field in T.fields {
|
$for field in T.fields {
|
||||||
if field.name in params && params[field.name] != '' {
|
if field.name in params && params[field.name] != '' {
|
||||||
|
|
@ -30,7 +26,6 @@ pub fn patch_from_params<T>(mut o T, params map[string]string) ? {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// params_from<T> converts a given T struct into a map of strings.
|
|
||||||
pub fn params_from<T>(o &T) map[string]string {
|
pub fn params_from<T>(o &T) map[string]string {
|
||||||
mut out := map[string]string{}
|
mut out := map[string]string{}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,3 +64,12 @@ pub fn pretty_bytes(bytes int) string {
|
||||||
|
|
||||||
return '${n:.2}${util.prefixes[i]}'
|
return '${n:.2}${util.prefixes[i]}'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn struct_to_map<T>(o T) map[string]string {
|
||||||
|
mut m := map[string]string{}
|
||||||
|
|
||||||
|
$for field in T.fields {
|
||||||
|
m[field.name] = o.$(field.name).str()
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue