Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
regen
mlmanager
Commits
7ed4b4ab
Commit
7ed4b4ab
authored
Nov 24, 2016
by
Leonard Techel
Browse files
Move the provider switch into the provider package
parent
4f948770
Changes
2
Hide whitespace changes
Inline
Side-by-side
app.go
View file @
7ed4b4ab
...
...
@@ -25,6 +25,11 @@ type DBConfig struct {
Args
string
`json:"args"`
}
type
ProviderConfig
struct
{
Provider
string
`json:"provider"`
Config
json
.
RawMessage
`json:"conf"`
}
type
ML
struct
{
Id
string
`json:"id"`
Title
map
[
string
]
string
`json:"title"`
...
...
@@ -32,9 +37,8 @@ type ML struct {
}
type
MLConfig
struct
{
Provider
string
`json:"provider"`
Config
json
.
RawMessage
`json:"conf"`
Lists
[]
ML
`json:"lists"`
ProviderConfig
Lists
[]
ML
`json:"lists"`
}
type
AppConfig
struct
{
...
...
@@ -95,26 +99,10 @@ func CreateApp(cfg AppConfig) (app *App) {
ctx
.
Data
[
"db"
]
=
db
ctx
.
Data
[
"app"
]
=
app
})
m
.
Use
(
func
(
ctx
*
macaron
.
Context
)
{
var
ml
mailinglistprovider
.
MailinglistProvider
if
app
.
cfg
.
Mailinglists
.
Provider
==
"mailman2"
{
var
cfg
mailinglistprovider
.
Mailman2ProviderConfig
err
:=
json
.
Unmarshal
(
app
.
cfg
.
Mailinglists
.
Config
,
&
cfg
)
if
err
!=
nil
{
panic
(
err
)
}
ml
,
err
=
mailinglistprovider
.
CreateMailman2Provider
(
cfg
)
if
err
!=
nil
{
panic
(
err
)
}
}
ctx
.
MapTo
(
ml
,
(
*
mailinglistprovider
.
MailinglistProvider
)(
nil
))
})
m
.
Use
(
mailinglistprovider
.
Mount
(
app
.
cfg
.
Mailinglists
.
Provider
,
app
.
cfg
.
Mailinglists
.
Config
))
auth
:=
remoteauthprovider
.
CreateOAuth2AuthProvider
(
m
,
db
,
app
.
cfg
.
OAuth2
)
m
.
Group
(
"/user"
,
func
()
{
m
.
Combo
(
"/login"
)
.
Get
(
auth
.
GetLogin
)
.
...
...
mailinglistprovider/mailinglistprovider.go
View file @
7ed4b4ab
package
mailinglistprovider
import
(
"encoding/json"
"gopkg.in/macaron.v1"
)
type
MailinglistProvider
interface
{
IsSubscribed
(
email
string
)
bool
Subscribe
(
email
string
)
Unsubscribe
(
email
string
)
}
// Use this function using app.Use() on your macaron app to mount auth providers
func
Mount
(
provider
string
,
config
json
.
RawMessage
)
func
(
*
macaron
.
Context
)
{
return
func
(
ctx
*
macaron
.
Context
)
{
var
ml
MailinglistProvider
switch
provider
{
case
"mailman2"
:
var
cfg
Mailman2ProviderConfig
err
:=
json
.
Unmarshal
(
config
,
&
cfg
)
if
err
!=
nil
{
panic
(
err
)
}
ml
,
err
=
CreateMailman2Provider
(
cfg
)
if
err
!=
nil
{
panic
(
err
)
}
break
default
:
panic
(
"unknown mailinglist provider"
)
}
ctx
.
MapTo
(
ml
,
(
*
MailinglistProvider
)(
nil
))
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment