Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
i3going-on
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Kevin Lyda
i3going-on
Commits
7496e53a
Unverified
Commit
7496e53a
authored
2 years ago
by
Kevin Lyda
Browse files
Options
Downloads
Patches
Plain Diff
Initial pass as parsing config.
parent
be1365a0
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
config/main.go
+118
-0
118 additions, 0 deletions
config/main.go
doc/config.sample.yaml
+12
-0
12 additions, 0 deletions
doc/config.sample.yaml
with
130 additions
and
0 deletions
config/main.go
0 → 100644
+
118
−
0
View file @
7496e53a
package
main
import
(
"fmt"
"os"
"gopkg.in/yaml.v3"
)
type
ParamsInterface
interface
{
Name
()
string
OnClick
()
string
}
type
Module
struct
{
Module
string
`yaml:"module"`
Name
string
`yaml:"name"`
OnClick
string
`yaml:"on-click"`
Params
ParamsInterface
`yaml:"-"`
}
type
M
Module
type
Params
struct
{
*
M
`yaml:",inline"`
Params
yaml
.
Node
`yaml:"params"`
}
type
DateMod
struct
{
name
string
onclick
string
Format
string
`yaml:"format"`
}
type
TextMod
struct
{
name
string
onclick
string
//Name string `yaml:"-"`
//OnClick string `yaml:"-"`
Text
string
`yaml:"text"`
Color
string
`yaml:"color"`
}
func
NewDate
(
m
*
Module
)
*
DateMod
{
d
:=
&
DateMod
{
name
:
m
.
Name
,
onclick
:
m
.
OnClick
,
}
if
d
.
name
==
""
{
d
.
name
=
"date"
}
return
d
}
func
(
d
*
DateMod
)
Name
()
string
{
return
d
.
name
}
func
(
d
*
DateMod
)
OnClick
()
string
{
return
d
.
onclick
}
func
NewText
(
m
*
Module
)
*
TextMod
{
t
:=
&
TextMod
{
name
:
m
.
Name
,
onclick
:
m
.
OnClick
,
}
if
t
.
name
==
""
{
t
.
name
=
"text"
}
return
t
}
func
(
t
*
TextMod
)
Name
()
string
{
return
t
.
name
}
func
(
t
*
TextMod
)
OnClick
()
string
{
return
t
.
onclick
}
type
Modules
struct
{
Modules
[]
Module
`yaml:"modules"`
}
func
(
m
*
Module
)
UnmarshalYAML
(
node
*
yaml
.
Node
)
error
{
params
:=
&
Params
{
M
:
(
*
M
)(
m
)}
if
err
:=
node
.
Decode
(
params
);
err
!=
nil
{
return
err
}
switch
params
.
Module
{
case
"date"
:
m
.
Params
=
NewDate
(
m
)
case
"text"
:
m
.
Params
=
NewText
(
m
)
default
:
panic
(
"module unknown"
)
}
return
params
.
Params
.
Decode
(
m
.
Params
)
}
func
main
()
{
config
,
err
:=
os
.
Open
(
os
.
Args
[
1
])
if
err
!=
nil
{
panic
(
err
)
}
defer
config
.
Close
()
configParser
:=
yaml
.
NewDecoder
(
config
)
cfg
:=
&
Modules
{}
err
=
configParser
.
Decode
(
&
cfg
)
if
err
!=
nil
{
panic
(
err
)
}
for
_
,
m
:=
range
cfg
.
Modules
{
fmt
.
Printf
(
"%s:%s:%s
\n
"
,
m
.
Module
,
m
.
Name
,
m
.
Params
.
Name
())
}
}
This diff is collapsed.
Click to expand it.
doc/config.sample.yaml
0 → 100644
+
12
−
0
View file @
7496e53a
---
modules
:
-
module
:
text
name
:
post
params
:
text
:
"
post"
color
:
"
#11ff11"
on-click
:
xdg-open https://mastodon.ie/
-
module
:
date
params
:
format
:
06-05-04 15:02
on-click
:
xdg-open https://calendar.google.com/
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment