Skip to content

Commit

Permalink
gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
romain-dartigues committed May 15, 2024
1 parent 60d24be commit e5685bf
Show file tree
Hide file tree
Showing 43 changed files with 272 additions and 256 deletions.
110 changes: 55 additions & 55 deletions bin/doc-generator/doc-generator.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package main

import (
"path"
"os"
. "github.com/cloudfoundry-community/gautocloud/test-utils"
_ "github.com/cloudfoundry-community/gautocloud/connectors/all"
"github.com/cloudfoundry-community/gautocloud"
_ "github.com/cloudfoundry-community/gautocloud/connectors/all"
. "github.com/cloudfoundry-community/gautocloud/test-utils"
"html/template"
"strings"
"os"
"path"
"reflect"
"sort"
"runtime"
"sort"
"strings"
)

type DocStruct struct {
Expand Down Expand Up @@ -55,26 +55,26 @@ type GlobalDoc struct {

func before() {
os.Setenv("MYSQL_URL", CreateEnvValue(ServiceUrl{
Type: "mysql",
User: "user",
Type: "mysql",
User: "user",
Password: "password",
Port: 3406,
Target: "mydb",
Port: 3406,
Target: "mydb",
}))
os.Setenv("POSTGRES_URL", CreateEnvValue(ServiceUrl{
Type: "postgres",
User: "user",
Type: "postgres",
User: "user",
Password: "password",
Port: 5532,
Target: "mydb",
Options: "sslmode=disable",
Port: 5532,
Target: "mydb",
Options: "sslmode=disable",
}))
os.Setenv("MSSQL_URL", CreateEnvValue(ServiceUrl{
Type: "sqlserver",
User: "sa",
Type: "sqlserver",
User: "sa",
Password: "password",
Port: 1433,
Target: "test",
Port: 1433,
Target: "test",
}))
os.Setenv("SSO_TOKEN_URI", "http://localhost/tokenUri")
os.Setenv("SSO_AUTH_URI", "http://localhost/authUri")
Expand All @@ -84,37 +84,37 @@ func before() {
os.Setenv("SSO_GRANT_TYPE", "grant1,grant2")
os.Setenv("SSO_SCOPES", "scope1,scope2")
os.Setenv("MONGODB_URL", CreateEnvValue(ServiceUrl{
Type: "mongo",
Port: 27017,
Type: "mongo",
Port: 27017,
Target: "test",
}))
os.Setenv("ORACLE_URL", CreateEnvValue(ServiceUrl{
Type: "oci",
Port: 27017,
Type: "oci",
Port: 27017,
Target: "test",
}))
os.Setenv("REDIS_URL", CreateEnvValue(ServiceUrl{
Type: "redis",
User: "redis",
Type: "redis",
User: "redis",
Password: "redis",
Port: 6379,
Port: 6379,
}))
os.Setenv("AMQP_URL", CreateEnvValue(ServiceUrl{
Type: "amqp",
User: "user",
Type: "amqp",
User: "user",
Password: "password",
Port: 5672,
Port: 5672,
}))
os.Setenv("SMTP_URL", CreateEnvValue(ServiceUrl{
Type: "smtp",
Port: 587,
}))
os.Setenv("S3_URL", CreateEnvValue(ServiceUrl{
Type: "s3",
User: "accessKey1",
Type: "s3",
User: "accessKey1",
Password: "verySecretKey1",
Port: 8090,
Target: "bucket",
Port: 8090,
Target: "bucket",
}))
gautocloud.ReloadConnectors()
}
Expand All @@ -129,7 +129,7 @@ func main() {
docs := getDocMap()
mk := make([]string, len(docs))
i := 0
for k, _ := range docs {
for k := range docs {
mk[i] = k
i++
}
Expand All @@ -141,21 +141,21 @@ func main() {
summaries[index] = Summary{
Name: docs[key].Name,
Slug: toSlug(docs[key].Name),
Sub: make([]Summary, 0),
Sub: make([]Summary, 0),
}
for _, docConn := range docs[key].Connectors {
summary := summaries[index]
summary.Sub = append(summary.Sub, Summary{
Name: docConn.Name,
Slug: toSlug(docConn.Name),
Sub: make([]Summary, 0),
Sub: make([]Summary, 0),
})
summaries[index] = summary
}
}
gd := GlobalDoc{
DocsConnector: docSlice,
Summaries: summaries,
Summaries: summaries,
}
err = tmpl.Execute(os.Stdout, gd)
fatalIf(err)
Expand All @@ -168,13 +168,13 @@ func getDocMap() map[string]Doc {
docs := make(map[string]Doc)
for id, conn := range gautocloud.Connectors() {
rootIdSplit := strings.Split(id, ":")
rootId := rootIdSplit[len(rootIdSplit) - 1]
rootId := rootIdSplit[len(rootIdSplit)-1]
if _, ok := docs[rootId]; !ok {
docs[rootId] = Doc{
Name: strings.Title(rootId),
Name: strings.Title(rootId),
RespondName: conn.Name(),
RespondTags: conn.Tags(),
Connectors: make([]DocConnector, 0),
Connectors: make([]DocConnector, 0),
}
}
connType := reflect.TypeOf(conn).Elem()
Expand All @@ -201,7 +201,7 @@ func getDocMap() map[string]Doc {
typeWrapped := ""
if givenValue.NumField() == 1 {
typeShortSplit := strings.Split(givenValue.Field(0).Type().String(), ".")
typeShort := typeShortSplit[len(typeShortSplit) - 1]
typeShort := typeShortSplit[len(typeShortSplit)-1]
if len(typeShortSplit) > 1 && typeShort == givenValue.Type().Field(0).Name {
typeField := givenValue.Field(0).Type()
if typeField.Kind() == reflect.Ptr {
Expand All @@ -223,18 +223,18 @@ func getDocMap() map[string]Doc {
globalType = pkgSplit[4]
}
connDoc := DocConnector{
Name: strings.Title(rootId + " - " + connName),
Id: conn.Id(),
Pkg: pkgConn,
TypeName: givenType.String(),
TypePkg: giventTypePkg.PkgPath(),
Name: strings.Title(rootId + " - " + connName),
Id: conn.Id(),
Pkg: pkgConn,
TypeName: givenType.String(),
TypePkg: giventTypePkg.PkgPath(),
TypeWrapped: typeWrapped,
DocUrl: docUrl,
Tip: tip,
GlobalType: strings.Title(globalType),
SimpleName: strings.Title(connName),
DocUrl: docUrl,
Tip: tip,
GlobalType: strings.Title(globalType),
SimpleName: strings.Title(connName),
StructGiven: generateDocStruct(givenData),
Closeable: isCloseable(givenData),
Closeable: isCloseable(givenData),
}
doc := docs[rootId]
connectors := append(doc.Connectors, connDoc)
Expand Down Expand Up @@ -284,7 +284,7 @@ func generateDocStruct(data interface{}) DocStruct {
nameSplit := strings.Split(givenType.String(), ".")

structGiven := DocStruct{
Name: nameSplit[len(nameSplit) - 1],
Name: nameSplit[len(nameSplit)-1],
}
fields := make([]DocField, 0)
v := reflect.ValueOf(data)
Expand All @@ -304,8 +304,8 @@ func generateDocStruct(data interface{}) DocStruct {
docUrl = "See doc: " + docUrl
}
fields = append(fields, DocField{
Name: tField.Name,
Type: vField.Type().String(),
Name: tField.Name,
Type: vField.Type().String(),
Comment: docUrl,
})
}
Expand All @@ -326,4 +326,4 @@ func (d DocConnectors) Less(i, j int) bool {
}
func (d DocConnectors) Swap(i, j int) {
d[i], d[j] = d[j], d[i]
}
}
2 changes: 1 addition & 1 deletion cloudenv/cloudenv.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// It manages the detection of the environment but also the detections of services asked by a Loader.
// It manages the detection of the environment but also the detections of services asked by a Loader.
package cloudenv

import "regexp"
Expand Down
10 changes: 5 additions & 5 deletions cloudenv/env_var_cloudenv.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package cloudenv

import (
"bytes"
"encoding/json"
"os"
"strings"
"encoding/json"
"bytes"
)

type EnvVarCloudEnv struct {
Expand Down Expand Up @@ -33,20 +33,20 @@ func (c *EnvVarCloudEnv) InitEnv(environ []string) {
for _, envVar := range environ {
splitEnv := strings.Split(envVar, "=")
envVars = append(envVars, EnvVar{
Key: strings.ToLower(splitEnv[0]),
Key: strings.ToLower(splitEnv[0]),
Value: strings.TrimSpace(strings.Join(splitEnv[1:], "=")),
})
}
c.envVars = envVars
}
func (c EnvVarCloudEnv) GetServicesFromTags(tags []string) ([]Service) {
func (c EnvVarCloudEnv) GetServicesFromTags(tags []string) []Service {
services := make([]Service, 0)
for _, tag := range tags {
services = append(services, c.getServicesFromPrefix(tag)...)
}
return services
}
func (c EnvVarCloudEnv) GetServicesFromName(name string) ([]Service) {
func (c EnvVarCloudEnv) GetServicesFromName(name string) []Service {
return c.getServicesFromPrefix(name)
}
func (c EnvVarCloudEnv) getServicesFromPrefix(prefix string) []Service {
Expand Down
10 changes: 5 additions & 5 deletions cloudenv/fake/fake_cloudenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ type FakeCloudEnv struct {

func NewFakeCloudEnv() cloudenv.CloudEnv {
return &FakeCloudEnv{
services: make([]cloudenv.Service, 0),
services: make([]cloudenv.Service, 0),
inCloudEnv: true,
callLoad: 0,
callLoad: 0,
}
}
func (c FakeCloudEnv) Name() string {
return "fakecloudenv"
}
func (c FakeCloudEnv) GetServicesFromTags(tags []string) ([]cloudenv.Service) {
func (c FakeCloudEnv) GetServicesFromTags(tags []string) []cloudenv.Service {
return c.services
}
func (c FakeCloudEnv) GetServicesFromName(name string) ([]cloudenv.Service) {
func (c FakeCloudEnv) GetServicesFromName(name string) []cloudenv.Service {
return c.services
}
func (c *FakeCloudEnv) SetAppInfo(appInfo cloudenv.AppInfo) {
Expand All @@ -51,4 +51,4 @@ func (c *FakeCloudEnv) Load() error {
}
func (c FakeCloudEnv) GetAppInfo() cloudenv.AppInfo {
return c.appInfo
}
}
15 changes: 7 additions & 8 deletions connectors/all/init.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package all

import (
_ "github.com/cloudfoundry-community/gautocloud/connectors/databases/gorm"
_ "github.com/cloudfoundry-community/gautocloud/connectors/databases"
_ "github.com/cloudfoundry-community/gautocloud/connectors/databases/client"
_ "github.com/cloudfoundry-community/gautocloud/connectors/amqp"
_ "github.com/cloudfoundry-community/gautocloud/connectors/amqp/client"
_ "github.com/cloudfoundry-community/gautocloud/connectors/smtp"
_ "github.com/cloudfoundry-community/gautocloud/connectors/smtp/client"
_ "github.com/cloudfoundry-community/gautocloud/connectors/objstorage"
_ "github.com/cloudfoundry-community/gautocloud/connectors/objstorage/client"
_ "github.com/cloudfoundry-community/gautocloud/connectors/auth"
_ "github.com/cloudfoundry-community/gautocloud/connectors/auth/config"
_ "github.com/cloudfoundry-community/gautocloud/connectors/databases"
_ "github.com/cloudfoundry-community/gautocloud/connectors/databases/client"
_ "github.com/cloudfoundry-community/gautocloud/connectors/databases/gorm"
_ "github.com/cloudfoundry-community/gautocloud/connectors/objstorage"
_ "github.com/cloudfoundry-community/gautocloud/connectors/objstorage/client"
_ "github.com/cloudfoundry-community/gautocloud/connectors/smtp"
_ "github.com/cloudfoundry-community/gautocloud/connectors/smtp/client"
)

2 changes: 1 addition & 1 deletion connectors/amqp/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package amqp

import (
"github.com/cloudfoundry-community/gautocloud"
"github.com/cloudfoundry-community/gautocloud/connectors/amqp/raw"
_ "github.com/cloudfoundry-community/gautocloud/connectors/amqp/client"
"github.com/cloudfoundry-community/gautocloud/connectors/amqp/raw"
)

func init() {
Expand Down
11 changes: 5 additions & 6 deletions connectors/auth/config/oauth2/config_connector.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package oauth2

import (
"github.com/cloudfoundry-community/gautocloud"
"github.com/cloudfoundry-community/gautocloud/connectors"
"github.com/cloudfoundry-community/gautocloud/connectors/auth/raw"
"github.com/cloudfoundry-community/gautocloud"
"golang.org/x/oauth2"
. "github.com/cloudfoundry-community/gautocloud/connectors/auth/schema"
"golang.org/x/oauth2"
)

func init() {
Expand Down Expand Up @@ -37,11 +37,11 @@ func (c Oauth2ConfigConnector) Load(schema interface{}) (interface{}, error) {
}
fSchema := schema.(Oauth2Schema)
config := &oauth2.Config{
ClientID: fSchema.ClientId,
ClientID: fSchema.ClientId,
ClientSecret: fSchema.ClientSecret,
Scopes: fSchema.Scopes,
Scopes: fSchema.Scopes,
Endpoint: oauth2.Endpoint{
AuthURL: fSchema.AuthorizationUri,
AuthURL: fSchema.AuthorizationUri,
TokenURL: fSchema.TokenUri,
},
}
Expand All @@ -50,4 +50,3 @@ func (c Oauth2ConfigConnector) Load(schema interface{}) (interface{}, error) {
func (c Oauth2ConfigConnector) Schema() interface{} {
return c.rawConn.Schema()
}

2 changes: 1 addition & 1 deletion connectors/auth/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ import (

func init() {
gautocloud.RegisterConnector(raw.NewOauth2RawConnector())
}
}
1 change: 0 additions & 1 deletion connectors/auth/raw/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ func (c Oauth2RawConnector) Load(schema interface{}) (interface{}, error) {
func (c Oauth2RawConnector) Schema() interface{} {
return Oauth2Schema{}
}

8 changes: 5 additions & 3 deletions connectors/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import "github.com/cloudfoundry-community/gautocloud/interceptor"
// this is the interface to be implemented to create a new connector
// You should add an init function in the same package of your connector and register it automatically in gautocloud when importing your connector
// Example of init function:
// func init() {
// gautocloud.RegisterConnector(NewMyConnector())
// }
//
// func init() {
// gautocloud.RegisterConnector(NewMyConnector())
// }
//
// see implementation of any raw connectors to see how to implement a connector
type Connector interface {
// This is the id of your connector and it must be unique and not have the same id of another connector
Expand Down
Loading

0 comments on commit e5685bf

Please sign in to comment.