Skip to content

Commit

Permalink
refactor: Use info.yaml to manage plugin configuration information
Browse files Browse the repository at this point in the history
  • Loading branch information
robinv8 authored and kumfo committed Jul 10, 2024
1 parent 15832b4 commit be49ab5
Show file tree
Hide file tree
Showing 30 changed files with 912 additions and 10 deletions.
1 change: 1 addition & 0 deletions connector-apache/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/apache/incubator-answer v1.3.1-0.20240506084933-9681c026adfe
github.com/apache/incubator-answer-plugins/util v0.0.0-00010101000000-000000000000
github.com/segmentfault/pacman v1.0.5-0.20230822083413-c0075a2d401f
gopkg.in/yaml.v2 v2.4.0
)

require (
Expand Down
53 changes: 53 additions & 0 deletions connector-apache/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package apache

import (
"fmt"
"os"
"path/filepath"
"runtime"

"gopkg.in/yaml.v2"
)

type Info struct {
SlugName string `yaml:"slug_name"`
Type string `yaml:"type"`
Version string `yaml:"version"`
Author string `yaml:"author"`
Link string `yaml:"link"`
}

func (c *Info) getInfo() *Info {
_, filename, _, _ := runtime.Caller(0)
wd := filepath.Dir(filename)

yamlFilePath := filepath.Join(wd, "info.yaml")
yamlFile, err := os.ReadFile(yamlFilePath)
if err != nil {
fmt.Println(err)
}
err = yaml.Unmarshal(yamlFile, c)
if err != nil {
fmt.Println(err)
}
return c
}
1 change: 1 addition & 0 deletions connector-basic/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/segmentfault/pacman v1.0.5-0.20230822083413-c0075a2d401f
github.com/tidwall/gjson v1.14.4
golang.org/x/oauth2 v0.4.0
gopkg.in/yaml.v2 v2.4.0
)

require (
Expand Down
53 changes: 53 additions & 0 deletions connector-basic/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package basic

import (
"fmt"
"os"
"path/filepath"
"runtime"

"gopkg.in/yaml.v2"
)

type Info struct {
SlugName string `yaml:"slug_name"`
Type string `yaml:"type"`
Version string `yaml:"version"`
Author string `yaml:"author"`
Link string `yaml:"link"`
}

func (c *Info) getInfo() *Info {
_, filename, _, _ := runtime.Caller(0)
wd := filepath.Dir(filename)

yamlFilePath := filepath.Join(wd, "info.yaml")
yamlFile, err := os.ReadFile(yamlFilePath)
if err != nil {
fmt.Println(err)
}
err = yaml.Unmarshal(yamlFile, c)
if err != nil {
fmt.Println(err)
}
return c
}
1 change: 1 addition & 0 deletions connector-dingtalk/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/apache/incubator-answer v1.3.1-0.20240506084933-9681c026adfe
github.com/apache/incubator-answer-plugins/util v0.0.0-00010101000000-000000000000
github.com/segmentfault/pacman v1.0.5-0.20230822083413-c0075a2d401f
gopkg.in/yaml.v2 v2.4.0
)

require (
Expand Down
53 changes: 53 additions & 0 deletions connector-dingtalk/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package dingtalk

import (
"fmt"
"os"
"path/filepath"
"runtime"

"gopkg.in/yaml.v2"
)

type Info struct {
SlugName string `yaml:"slug_name"`
Type string `yaml:"type"`
Version string `yaml:"version"`
Author string `yaml:"author"`
Link string `yaml:"link"`
}

func (c *Info) getInfo() *Info {
_, filename, _, _ := runtime.Caller(0)
wd := filepath.Dir(filename)

yamlFilePath := filepath.Join(wd, "info.yaml")
yamlFile, err := os.ReadFile(yamlFilePath)
if err != nil {
fmt.Println(err)
}
err = yaml.Unmarshal(yamlFile, c)
if err != nil {
fmt.Println(err)
}
return c
}
1 change: 1 addition & 0 deletions connector-github/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/google/go-github/v50 v50.1.0
github.com/segmentfault/pacman v1.0.5-0.20230822083413-c0075a2d401f
golang.org/x/oauth2 v0.4.0
gopkg.in/yaml.v2 v2.4.0
)

require (
Expand Down
53 changes: 53 additions & 0 deletions connector-github/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package github

import (
"fmt"
"os"
"path/filepath"
"runtime"

"gopkg.in/yaml.v2"
)

type Info struct {
SlugName string `yaml:"slug_name"`
Type string `yaml:"type"`
Version string `yaml:"version"`
Author string `yaml:"author"`
Link string `yaml:"link"`
}

func (c *Info) getInfo() *Info {
_, filename, _, _ := runtime.Caller(0)
wd := filepath.Dir(filename)

yamlFilePath := filepath.Join(wd, "info.yaml")
yamlFile, err := os.ReadFile(yamlFilePath)
if err != nil {
fmt.Println(err)
}
err = yaml.Unmarshal(yamlFile, c)
if err != nil {
fmt.Println(err)
}
return c
}
1 change: 1 addition & 0 deletions connector-google/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/apache/incubator-answer v1.3.1-0.20240506084933-9681c026adfe
github.com/apache/incubator-answer-plugins/util v0.0.0-00010101000000-000000000000
golang.org/x/oauth2 v0.4.0
gopkg.in/yaml.v2 v2.4.0
)

require (
Expand Down
53 changes: 53 additions & 0 deletions connector-google/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package google

import (
"fmt"
"os"
"path/filepath"
"runtime"

"gopkg.in/yaml.v2"
)

type Info struct {
SlugName string `yaml:"slug_name"`
Type string `yaml:"type"`
Version string `yaml:"version"`
Author string `yaml:"author"`
Link string `yaml:"link"`
}

func (c *Info) getInfo() *Info {
_, filename, _, _ := runtime.Caller(0)
wd := filepath.Dir(filename)

yamlFilePath := filepath.Join(wd, "info.yaml")
yamlFile, err := os.ReadFile(yamlFilePath)
if err != nil {
fmt.Println(err)
}
err = yaml.Unmarshal(yamlFile, c)
if err != nil {
fmt.Println(err)
}
return c
}
5 changes: 0 additions & 5 deletions editor-chart/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm
github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
Expand All @@ -48,7 +47,6 @@ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02
github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk=
github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
Expand All @@ -67,7 +65,6 @@ github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNc
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/segmentfault/pacman v1.0.5-0.20230822083413-c0075a2d401f h1:9f2Bjf6bdMvNyUop32wAGJCdp+Jdm/d6nKBYvFvkRo0=
github.com/segmentfault/pacman v1.0.5-0.20230822083413-c0075a2d401f/go.mod h1:5lNp5REd8QMThmBUvR3Fi9Y3AsOB4GRq7soCB4QLqOs=
github.com/segmentfault/pacman/contrib/i18n v0.0.0-20230516093754-b76aef1c1150 h1:OEuW1D7RGDE0CZDr0oGMw9Eiq7fAbD9C4WMrvSixamk=
Expand All @@ -83,7 +80,6 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
Expand Down Expand Up @@ -134,7 +130,6 @@ google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cn
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
Expand Down
Loading

0 comments on commit be49ab5

Please sign in to comment.