1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-10 21:45:57 +00:00

Embrace the weekend- Update to rc.3 | Read the HISTORY.md

This commit is contained in:
Makis Maropoulos
2016-06-24 01:34:49 +03:00
parent 4a446ac1e2
commit f83b532835
50 changed files with 142 additions and 3812 deletions

View File

@@ -1,41 +0,0 @@
package config
import (
"time"
"github.com/imdario/mergo"
)
const (
// DefaultBasicAuthRealm is "Authorization Required"
DefaultBasicAuthRealm = "Authorization Required"
// DefaultBasicAuthContextKey is the "auth"
// this key is used to do context.Set("auth", theUsernameFromBasicAuth)
DefaultBasicAuthContextKey = "auth"
)
// BasicAuth the configs for the basicauth middleware
type BasicAuth struct {
// Users a map of login and the value (username/password)
Users map[string]string
// Realm http://tools.ietf.org/html/rfc2617#section-1.2. Default is "Authorization Required"
Realm string
// ContextKey the key for ctx.GetString(...). Default is 'auth'
ContextKey string
// Expires expiration duration, default is 0 never expires
Expires time.Duration
}
// DefaultBasicAuth returns the default configs for the BasicAuth middleware
func DefaultBasicAuth() BasicAuth {
return BasicAuth{make(map[string]string), DefaultBasicAuthRealm, DefaultBasicAuthContextKey, 0}
}
// MergeSingle merges the default with the given config and returns the result
func (c BasicAuth) MergeSingle(cfg BasicAuth) (config BasicAuth) {
config = cfg
mergo.Merge(&config, c)
return
}

View File

@@ -1,45 +0,0 @@
package config
import "github.com/imdario/mergo"
// Editor the configs for the Editor plugin
type Editor struct {
// Host if empty used the iris server's host
Host string
// Port if 0 4444
Port int
// WorkingDir if empty "./"
WorkingDir string
// Username if empty iris
Username string
// Password if empty admin!123
Password string
}
// DefaultEditor returns the default configs for the Editor plugin
func DefaultEditor() Editor {
return Editor{"", 4444, "." + pathSeparator, DefaultUsername, DefaultPassword}
}
// Merge merges the default with the given config and returns the result
func (c Editor) Merge(cfg []Editor) (config Editor) {
if len(cfg) > 0 {
config = cfg[0]
mergo.Merge(&config, c)
} else {
_default := c
config = _default
}
return
}
// MergeSingle merges the default with the given config and returns the result
func (c Editor) MergeSingle(cfg Editor) (config Editor) {
config = cfg
mergo.Merge(&config, c)
return
}

View File

@@ -101,13 +101,6 @@ type (
// Websocket contains the configs for Websocket's server integration
Websocket *Websocket
// Mail contains the configs for the mail sender service
Mail Mail
// OAuth the configs for the gothic oauth/oauth2 authentication for third-party websites
// See https://github.com/iris-contrib/gothic/blob/master/example/main.go
OAuth OAuth
// Server contains the configs for the http server
// Server configs are the only one which are setted inside base Iris package (from Listen, ListenTLS, ListenUNIX) NO from users
//
@@ -150,8 +143,6 @@ func Default() Iris {
Sessions: DefaultSessions(),
Render: DefaultRender(),
Websocket: DefaultWebsocket(),
Mail: DefaultMail(),
OAuth: DefaultOAuth(),
Server: DefaultServer(),
}
}

View File

@@ -1,40 +0,0 @@
package config
import "github.com/imdario/mergo"
var (
// DefaultUsername used for default (basic auth) username in IrisControl's & Editor's default configuration
DefaultUsername = "iris"
// DefaultPassword used for default (basic auth) password in IrisControl's & Editor's default configuration
DefaultPassword = "admin!123"
)
// IrisControl the options which iris control needs
// contains the port (int) and authenticated users with their passwords (map[string]string)
type IrisControl struct {
// Port the port
Port int
// Users the authenticated users, [username]password
Users map[string]string
}
// DefaultIrisControl returns the default configs for IrisControl plugin
func DefaultIrisControl() IrisControl {
users := make(map[string]string, 0)
users[DefaultUsername] = DefaultPassword
return IrisControl{4000, users}
}
// Merge merges the default with the given config and returns the result
func (c IrisControl) Merge(cfg []IrisControl) (config IrisControl) {
if len(cfg) > 0 {
config = cfg[0]
mergo.Merge(&config, c)
} else {
_default := c
config = _default
}
return
}

View File

@@ -80,12 +80,12 @@ func DefaultLogger() Logger {
ColorFgDanger: int(color.FgHiRed),
ColorFgOther: int(color.FgHiYellow),
// background colors
ColorBgDefault: int(color.BgHiBlack),
ColorBgInfo: int(color.BgHiBlack),
ColorBgSuccess: int(color.BgHiBlack),
ColorBgWarning: int(color.BgHiBlack),
ColorBgDanger: int(color.BgHiWhite),
ColorBgOther: int(color.BgHiBlack),
ColorBgDefault: 0,
ColorBgInfo: 0,
ColorBgSuccess: 0,
ColorBgWarning: 0,
ColorBgDanger: 0,
ColorBgOther: 0,
// banner color
ColorFgBanner: int(color.FgHiBlue),
}

View File

@@ -1,31 +0,0 @@
package config
// Mail keeps the configs for mail sender service
type Mail struct {
// Host is the server mail host, IP or address
Host string
// Port is the listening port
Port int
// Username is the auth username@domain.com for the sender
Username string
// Password is the auth password for the sender
Password string
// FromAlias is the from part, if empty this is the first part before @ from the Username field
FromAlias string
// UseCommand enable it if you want to send e-mail with the mail command instead of smtp
//
// Host,Port & Password will be ignored
// ONLY FOR UNIX
UseCommand bool
}
// DefaultMail returns the default configs for Mail
// returns just an empty Mail struct
func DefaultMail() Mail {
return Mail{}
}
// IsValid returns true if the mail configs are valid
func (m Mail) IsValid() bool {
return (m.Host != "" && m.Port > 0 && m.Username != "" && m.Password != "") || m.UseCommand
}

View File

@@ -1,213 +0,0 @@
package config
import (
"github.com/imdario/mergo"
"github.com/markbates/goth"
"github.com/markbates/goth/providers/amazon"
"github.com/markbates/goth/providers/bitbucket"
"github.com/markbates/goth/providers/box"
"github.com/markbates/goth/providers/digitalocean"
"github.com/markbates/goth/providers/dropbox"
"github.com/markbates/goth/providers/facebook"
"github.com/markbates/goth/providers/github"
"github.com/markbates/goth/providers/gitlab"
"github.com/markbates/goth/providers/gplus"
"github.com/markbates/goth/providers/heroku"
"github.com/markbates/goth/providers/instagram"
"github.com/markbates/goth/providers/lastfm"
"github.com/markbates/goth/providers/linkedin"
"github.com/markbates/goth/providers/onedrive"
"github.com/markbates/goth/providers/paypal"
"github.com/markbates/goth/providers/salesforce"
"github.com/markbates/goth/providers/slack"
"github.com/markbates/goth/providers/soundcloud"
"github.com/markbates/goth/providers/spotify"
"github.com/markbates/goth/providers/steam"
"github.com/markbates/goth/providers/stripe"
"github.com/markbates/goth/providers/twitch"
"github.com/markbates/goth/providers/twitter"
"github.com/markbates/goth/providers/uber"
"github.com/markbates/goth/providers/wepay"
"github.com/markbates/goth/providers/yahoo"
"github.com/markbates/goth/providers/yammer"
)
const (
// DefaultAuthPath /auth
DefaultAuthPath = "/auth"
)
// OAuth the configs for the gothic oauth/oauth2 authentication for third-party websites
// All Key and Secret values are empty by default strings. Non-empty will be registered as Goth Provider automatically, by Iris
// the users can still register their own providers using goth.UseProviders
// contains the providers' keys (& secrets) and the relative auth callback url path(ex: "/auth" will be registered as /auth/:provider/callback)
//
type OAuth struct {
Path string
TwitterKey, TwitterSecret, TwitterName string
FacebookKey, FacebookSecret, FacebookName string
GplusKey, GplusSecret, GplusName string
GithubKey, GithubSecret, GithubName string
SpotifyKey, SpotifySecret, SpotifyName string
LinkedinKey, LinkedinSecret, LinkedinName string
LastfmKey, LastfmSecret, LastfmName string
TwitchKey, TwitchSecret, TwitchName string
DropboxKey, DropboxSecret, DropboxName string
DigitaloceanKey, DigitaloceanSecret, DigitaloceanName string
BitbucketKey, BitbucketSecret, BitbucketName string
InstagramKey, InstagramSecret, InstagramName string
BoxKey, BoxSecret, BoxName string
SalesforceKey, SalesforceSecret, SalesforceName string
AmazonKey, AmazonSecret, AmazonName string
YammerKey, YammerSecret, YammerName string
OneDriveKey, OneDriveSecret, OneDriveName string
YahooKey, YahooSecret, YahooName string
SlackKey, SlackSecret, SlackName string
StripeKey, StripeSecret, StripeName string
WepayKey, WepaySecret, WepayName string
PaypalKey, PaypalSecret, PaypalName string
SteamKey, SteamName string
HerokuKey, HerokuSecret, HerokuName string
UberKey, UberSecret, UberName string
SoundcloudKey, SoundcloudSecret, SoundcloudName string
GitlabKey, GitlabSecret, GitlabName string
}
// DefaultOAuth returns OAuth config, the fields of the iteral are zero-values ( empty strings)
func DefaultOAuth() OAuth {
return OAuth{
Path: DefaultAuthPath,
TwitterName: "twitter",
FacebookName: "facebook",
GplusName: "gplus",
GithubName: "github",
SpotifyName: "spotify",
LinkedinName: "linkedin",
LastfmName: "lastfm",
TwitchName: "twitch",
DropboxName: "dropbox",
DigitaloceanName: "digitalocean",
BitbucketName: "bitbucket",
InstagramName: "instagram",
BoxName: "box",
SalesforceName: "salesforce",
AmazonName: "amazon",
YammerName: "yammer",
OneDriveName: "onedrive",
YahooName: "yahoo",
SlackName: "slack",
StripeName: "stripe",
WepayName: "wepay",
PaypalName: "paypal",
SteamName: "steam",
HerokuName: "heroku",
UberName: "uber",
SoundcloudName: "soundcloud",
GitlabName: "gitlab",
} // this will be registered as /auth/:provider in the mux
}
// MergeSingle merges the default with the given config and returns the result
func (c OAuth) MergeSingle(cfg OAuth) (config OAuth) {
config = cfg
mergo.Merge(&config, c)
return
}
// GetAll returns the valid goth providers and the relative url paths (because the goth.Provider doesn't have a public method to get the Auth path...)
// we do the hard-core/hand checking here at the configs.
//
// receives one parameter which is the host from the server,ex: http://localhost:3000, will be used as prefix for the oauth callback
func (c OAuth) GetAll(vhost string) (providers []goth.Provider) {
getCallbackURL := func(providerName string) string {
return vhost + c.Path + "/" + providerName + "/callback"
}
//we could use a map but that's easier for the users because of code completion of their IDEs/editors
if c.TwitterKey != "" && c.TwitterSecret != "" {
println(getCallbackURL("twitter"))
providers = append(providers, twitter.New(c.TwitterKey, c.TwitterSecret, getCallbackURL(c.TwitterName)))
}
if c.FacebookKey != "" && c.FacebookSecret != "" {
providers = append(providers, facebook.New(c.FacebookKey, c.FacebookSecret, getCallbackURL(c.FacebookName)))
}
if c.GplusKey != "" && c.GplusSecret != "" {
providers = append(providers, gplus.New(c.GplusKey, c.GplusSecret, getCallbackURL(c.GplusName)))
}
if c.GithubKey != "" && c.GithubSecret != "" {
providers = append(providers, github.New(c.GithubKey, c.GithubSecret, getCallbackURL(c.GithubName)))
}
if c.SpotifyKey != "" && c.SpotifySecret != "" {
providers = append(providers, spotify.New(c.SpotifyKey, c.SpotifySecret, getCallbackURL(c.SpotifyName)))
}
if c.LinkedinKey != "" && c.LinkedinSecret != "" {
providers = append(providers, linkedin.New(c.LinkedinKey, c.LinkedinSecret, getCallbackURL(c.LinkedinName)))
}
if c.LastfmKey != "" && c.LastfmSecret != "" {
providers = append(providers, lastfm.New(c.LastfmKey, c.LastfmSecret, getCallbackURL(c.LastfmName)))
}
if c.TwitchKey != "" && c.TwitchSecret != "" {
providers = append(providers, twitch.New(c.TwitchKey, c.TwitchSecret, getCallbackURL(c.TwitchName)))
}
if c.DropboxKey != "" && c.DropboxSecret != "" {
providers = append(providers, dropbox.New(c.DropboxKey, c.DropboxSecret, getCallbackURL(c.DropboxName)))
}
if c.DigitaloceanKey != "" && c.DigitaloceanSecret != "" {
providers = append(providers, digitalocean.New(c.DigitaloceanKey, c.DigitaloceanSecret, getCallbackURL(c.DigitaloceanName)))
}
if c.BitbucketKey != "" && c.BitbucketSecret != "" {
providers = append(providers, bitbucket.New(c.BitbucketKey, c.BitbucketSecret, getCallbackURL(c.BitbucketName)))
}
if c.InstagramKey != "" && c.InstagramSecret != "" {
providers = append(providers, instagram.New(c.InstagramKey, c.InstagramSecret, getCallbackURL(c.InstagramName)))
}
if c.BoxKey != "" && c.BoxSecret != "" {
providers = append(providers, box.New(c.BoxKey, c.BoxSecret, getCallbackURL(c.BoxName)))
}
if c.SalesforceKey != "" && c.SalesforceSecret != "" {
providers = append(providers, salesforce.New(c.SalesforceKey, c.SalesforceSecret, getCallbackURL(c.SalesforceName)))
}
if c.AmazonKey != "" && c.AmazonSecret != "" {
providers = append(providers, amazon.New(c.AmazonKey, c.AmazonSecret, getCallbackURL(c.AmazonName)))
}
if c.YammerKey != "" && c.YammerSecret != "" {
providers = append(providers, yammer.New(c.YammerKey, c.YammerSecret, getCallbackURL(c.YammerName)))
}
if c.OneDriveKey != "" && c.OneDriveSecret != "" {
providers = append(providers, onedrive.New(c.OneDriveKey, c.OneDriveSecret, getCallbackURL(c.OneDriveName)))
}
if c.YahooKey != "" && c.YahooSecret != "" {
providers = append(providers, yahoo.New(c.YahooKey, c.YahooSecret, getCallbackURL(c.YahooName)))
}
if c.SlackKey != "" && c.SlackSecret != "" {
providers = append(providers, slack.New(c.SlackKey, c.SlackSecret, getCallbackURL(c.SlackName)))
}
if c.StripeKey != "" && c.StripeSecret != "" {
providers = append(providers, stripe.New(c.StripeKey, c.StripeSecret, getCallbackURL(c.StripeName)))
}
if c.WepayKey != "" && c.WepaySecret != "" {
providers = append(providers, wepay.New(c.WepayKey, c.WepaySecret, getCallbackURL(c.WepayName)))
}
if c.PaypalKey != "" && c.PaypalSecret != "" {
providers = append(providers, paypal.New(c.PaypalKey, c.PaypalSecret, getCallbackURL(c.PaypalName)))
}
if c.SteamKey != "" {
providers = append(providers, steam.New(c.SteamKey, getCallbackURL(c.SteamName)))
}
if c.HerokuKey != "" && c.HerokuSecret != "" {
providers = append(providers, heroku.New(c.HerokuKey, c.HerokuSecret, getCallbackURL(c.HerokuName)))
}
if c.UberKey != "" && c.UberSecret != "" {
providers = append(providers, uber.New(c.UberKey, c.UberSecret, getCallbackURL(c.UberName)))
}
if c.SoundcloudKey != "" && c.SoundcloudSecret != "" {
providers = append(providers, soundcloud.New(c.SoundcloudKey, c.SoundcloudSecret, getCallbackURL(c.SoundcloudName)))
}
if c.GitlabKey != "" && c.GitlabSecret != "" {
providers = append(providers, gitlab.New(c.GitlabKey, c.GitlabSecret, getCallbackURL(c.GithubName)))
}
return
}

View File

@@ -1,139 +0,0 @@
package config
import (
"os"
"reflect"
"github.com/imdario/mergo"
)
var (
pathSeparator = string(os.PathSeparator)
nodeModules = pathSeparator + "node_modules" + pathSeparator
)
type (
// Tsconfig the struct for tsconfig.json
Tsconfig struct {
CompilerOptions CompilerOptions `json:"compilerOptions"`
Exclude []string `json:"exclude"`
}
// CompilerOptions contains all the compiler options used by the tsc (typescript compiler)
CompilerOptions struct {
Declaration bool `json:"declaration"`
Module string `json:"module"`
Target string `json:"target"`
Watch bool `json:"watch"`
Charset string `json:"charset"`
Diagnostics bool `json:"diagnostics"`
EmitBOM bool `json:"emitBOM"`
EmitDecoratorMetadata bool `json:"emitDecoratorMetadata"`
ExperimentalDecorators bool `json:"experimentalDecorators"`
InlineSourceMap bool `json:"inlineSourceMap"`
InlineSources bool `json:"inlineSources"`
IsolatedModules bool `json:"isolatedModules"`
Jsx string `json:"jsx"`
ReactNamespace string `json:"reactNamespace"`
ListFiles bool `json:"listFiles"`
Locale string `json:"locale"`
MapRoot string `json:"mapRoot"`
ModuleResolution string `json:"moduleResolution"`
NewLine string `json:"newLine"`
NoEmit bool `json:"noEmit"`
NoEmitOnError bool `json:"noEmitOnError"`
NoEmitHelpers bool `json:"noEmitHelpers"`
NoImplicitAny bool `json:"noImplicitAny"`
NoLib bool `json:"noLib"`
NoResolve bool `json:"noResolve"`
SkipDefaultLibCheck bool `json:"skipDefaultLibCheck"`
OutDir string `json:"outDir"`
OutFile string `json:"outFile"`
PreserveConstEnums bool `json:"preserveConstEnums"`
Pretty bool `json:"pretty"`
RemoveComments bool `json:"removeComments"`
RootDir string `json:"rootDir"`
SourceMap bool `json:"sourceMap"`
SourceRoot string `json:"sourceRoot"`
StripInternal bool `json:"stripInternal"`
SuppressExcessPropertyErrors bool `json:"suppressExcessPropertyErrors"`
SuppressImplicitAnyIndexErrors bool `json:"suppressImplicitAnyIndexErrors"`
AllowUnusedLabels bool `json:"allowUnusedLabels"`
NoImplicitReturns bool `json:"noImplicitReturns"`
NoFallthroughCasesInSwitch bool `json:"noFallthroughCasesInSwitch"`
AllowUnreachableCode bool `json:"allowUnreachableCode"`
ForceConsistentCasingInFileNames bool `json:"forceConsistentCasingInFileNames"`
AllowSyntheticDefaultImports bool `json:"allowSyntheticDefaultImports"`
AllowJs bool `json:"allowJs"`
NoImplicitUseStrict bool `json:"noImplicitUseStrict"`
}
// Typescript the configs for the Typescript plugin
Typescript struct {
// Bin the path of the tsc binary file
// if empty then the plugin tries to find it
Bin string
// Dir the client side directory, which typescript (.ts) files are live
Dir string
// Ignore ignore folders, default is /node_modules/
Ignore string
// Tsconfig the typescript build configs, including the compiler's options
Tsconfig Tsconfig
// Editor the Editor plugin
Editor Editor
}
)
// CompilerArgs returns the CompilerOptions' contents of the Tsconfig
// it reads the json tags, add '--' at the start of each one and returns an array of strings
func (tsconfig Tsconfig) CompilerArgs() []string {
//val := reflect.ValueOf(tsconfig).Elem().FieldByName("CompilerOptions") -> for tsconfig *Tsconfig
val := reflect.ValueOf(tsconfig).FieldByName("CompilerOptions")
compilerOpts := make([]string, val.NumField())
for i := 0; i < val.NumField(); i++ {
typeField := val.Type().Field(i)
compilerOpts[i] = "--" + typeField.Tag.Get("json")
}
return compilerOpts
}
// DefaultTsconfig returns the default Tsconfig, with CompilerOptions module: commonjs, target: es5 and ignore the node_modules
func DefaultTsconfig() Tsconfig {
return Tsconfig{
CompilerOptions: CompilerOptions{
Module: "commonjs",
Target: "es5",
NoImplicitAny: false,
SourceMap: false,
},
Exclude: []string{"node_modules"},
}
}
// DefaultTypescript returns the default Options of the Typescript plugin
// Bin and Editor are setting in runtime via the plugin
func DefaultTypescript() Typescript {
root, err := os.Getwd()
if err != nil {
panic("Typescript Plugin: Cannot get the Current Working Directory !!! [os.getwd()]")
}
c := Typescript{Dir: root + pathSeparator, Ignore: nodeModules, Tsconfig: DefaultTsconfig()}
return c
}
// Merge merges the default with the given config and returns the result
func (c Typescript) Merge(cfg []Typescript) (config Typescript) {
if len(cfg) > 0 {
config = cfg[0]
mergo.Merge(&config, c)
} else {
_default := c
config = _default
}
return
}