فهرست منبع

moved back to a main.go file in root

Torkel Ödegaard 11 سال پیش
والد
کامیت
50164324f3
6فایلهای تغییر یافته به همراه22 افزوده شده و 45 حذف شده
  1. 3 0
      Makefile
  2. 3 4
      main.go
  3. 0 24
      pkg/cmd/grafana-pro/grafana-pro.go
  4. 1 1
      pkg/cmd/web.go
  5. 1 1
      pkg/routes/login/login_oauth.go
  6. 14 15
      pkg/social/social.go

+ 3 - 0
Makefile

@@ -5,4 +5,7 @@ all: build
 build:
 	go build ../pkg/cmd/grafana-pro/
 
+setup:
+	go get github.com/tools/godep
+
 

+ 3 - 4
grafana.go → main.go

@@ -4,8 +4,9 @@ import (
 	"os"
 	"runtime"
 
-	"github.com/codegangsta/cli"
 	"github.com/torkelo/grafana-pro/pkg/cmd"
+
+	"github.com/codegangsta/cli"
 )
 
 const APP_VER = "0.1.0 Alpha"
@@ -19,9 +20,7 @@ func main() {
 	app.Name = "Grafana Pro"
 	app.Usage = "Grafana Pro Service"
 	app.Version = APP_VER
-	app.Commands = []cli.Command{
-		cmd.CmdWeb,
-	}
+	app.Commands = []cli.Command{cmd.CmdWeb}
 	app.Flags = append(app.Flags, []cli.Flag{}...)
 	app.Run(os.Args)
 }

+ 0 - 24
pkg/cmd/grafana-pro/grafana-pro.go

@@ -1,24 +0,0 @@
-package main
-
-import (
-	"os"
-	"runtime"
-
-	"github.com/codegangsta/cli"
-)
-
-const APP_VER = "0.1.0 Alpha"
-
-func init() {
-	runtime.GOMAXPROCS(runtime.NumCPU())
-}
-
-func main() {
-	app := cli.NewApp()
-	app.Name = "Grafana Pro"
-	app.Usage = "Grafana Pro Service"
-	app.Version = APP_VER
-	app.Commands = []cli.Command{CmdWeb}
-	app.Flags = append(app.Flags, []cli.Flag{}...)
-	app.Run(os.Args)
-}

+ 1 - 1
pkg/cmd/grafana-pro/web.go → pkg/cmd/web.go

@@ -1,7 +1,7 @@
 // Copyright 2014 Unknwon
 // Copyright 2014 Torkel Ödegaard
 
-package main
+package cmd
 
 import (
 	"fmt"

+ 1 - 1
pkg/routes/login/login_oauth.go

@@ -32,7 +32,7 @@ func OAuthLogin(ctx *middleware.Context) {
 	log.Info("code: %v", code)
 
 	// handle call back
-	transport, err := connect.NewTransportWithCode(code)
+	transport, err := connect.NewTransportFromCode(code)
 	if err != nil {
 		ctx.Handle(500, "login.OAuthLogin(NewTransportWithCode)", err)
 		return

+ 14 - 15
pkg/social/social.go

@@ -6,10 +6,11 @@ import (
 	"strconv"
 	"strings"
 
-	"github.com/gogits/gogs/models"
-	"github.com/golang/oauth2"
 	"github.com/torkelo/grafana-pro/pkg/log"
+	"github.com/torkelo/grafana-pro/pkg/models"
 	"github.com/torkelo/grafana-pro/pkg/setting"
+
+	"github.com/golang/oauth2"
 )
 
 type BasicUserInfo struct {
@@ -25,7 +26,7 @@ type SocialConnector interface {
 	UserInfo(transport *oauth2.Transport) (*BasicUserInfo, error)
 
 	AuthCodeURL(state, accessType, prompt string) string
-	NewTransportWithCode(code string) (*oauth2.Transport, error)
+	NewTransportFromCode(code string) (*oauth2.Transport, error)
 }
 
 var (
@@ -58,15 +59,13 @@ func NewOAuthService() {
 			continue
 		}
 
-		opts := &oauth2.Options{
-			ClientID:     info.ClientId,
-			ClientSecret: info.ClientSecret,
-			RedirectURL:  strings.TrimSuffix(setting.AppUrl, "/") + SocialBaseUrl + name,
-			Scopes:       info.Scopes,
-		}
-
 		setting.OAuthService.OAuthInfos[name] = info
-		config, err := oauth2.NewConfig(opts, info.AuthUrl, info.TokenUrl)
+		options, err := oauth2.New(
+			oauth2.Client(info.ClientId, info.ClientSecret),
+			oauth2.Scope(info.Scopes...),
+			oauth2.Endpoint(info.AuthUrl, info.TokenUrl),
+			oauth2.RedirectURL(strings.TrimSuffix(setting.AppUrl, "/")+SocialBaseUrl+name),
+		)
 
 		if err != nil {
 			log.Error(3, "Failed to init oauth service", err)
@@ -76,19 +75,19 @@ func NewOAuthService() {
 		// GitHub.
 		if name == "github" {
 			setting.OAuthService.GitHub = true
-			SocialMap["github"] = &SocialGithub{Config: config}
+			SocialMap["github"] = &SocialGithub{Options: options}
 		}
 
 		// Google.
 		if name == "google" {
 			setting.OAuthService.Google = true
-			SocialMap["google"] = &SocialGoogle{Config: config}
+			SocialMap["google"] = &SocialGoogle{Options: options}
 		}
 	}
 }
 
 type SocialGithub struct {
-	*oauth2.Config
+	*oauth2.Options
 }
 
 func (s *SocialGithub) Type() int {
@@ -130,7 +129,7 @@ func (s *SocialGithub) UserInfo(transport *oauth2.Transport) (*BasicUserInfo, er
 //         \/             /_____/           \/
 
 type SocialGoogle struct {
-	*oauth2.Config
+	*oauth2.Options
 }
 
 func (s *SocialGoogle) Type() int {