use regex.MustCompile instead of dealing with the error

Michael Muré created

Change summary

bridge/core/auth/credential.go |  5 +----
bridge/core/bridge.go          | 10 ++--------
bridge/github/config.go        |  5 +----
bridge/gitlab/config.go        |  5 +----
bridge/launchpad/config.go     |  5 +----
5 files changed, 6 insertions(+), 24 deletions(-)

Detailed changes

bridge/core/auth/credential.go 🔗

@@ -171,10 +171,7 @@ func List(repo repository.RepoConfig, opts ...Option) ([]Credential, error) {
 		return nil, err
 	}
 
-	re, err := regexp.Compile(`^` + configKeyPrefix + `\.([^.]+)\.([^.]+(?:\.[^.]+)*)$`)
-	if err != nil {
-		panic(err)
-	}
+	re := regexp.MustCompile(`^` + configKeyPrefix + `\.([^.]+)\.([^.]+(?:\.[^.]+)*)$`)
 
 	mapped := make(map[string]map[string]string)
 

bridge/core/bridge.go 🔗

@@ -155,10 +155,7 @@ func ConfiguredBridges(repo repository.RepoConfig) ([]string, error) {
 		return nil, errors.Wrap(err, "can't read configured bridges")
 	}
 
-	re, err := regexp.Compile(bridgeConfigKeyPrefix + `.([^.]+)`)
-	if err != nil {
-		panic(err)
-	}
+	re := regexp.MustCompile(bridgeConfigKeyPrefix + `.([^.]+)`)
 
 	set := make(map[string]interface{})
 
@@ -194,10 +191,7 @@ func BridgeExist(repo repository.RepoConfig, name string) bool {
 
 // Remove a configured bridge
 func RemoveBridge(repo repository.RepoConfig, name string) error {
-	re, err := regexp.Compile(`^[a-zA-Z0-9]+`)
-	if err != nil {
-		panic(err)
-	}
+	re := regexp.MustCompile(`^[a-zA-Z0-9]+`)
 
 	if !re.MatchString(name) {
 		return fmt.Errorf("bad bridge fullname: %s", name)

bridge/github/config.go 🔗

@@ -287,10 +287,7 @@ func promptToken() (*auth.Token, error) {
 	fmt.Println("  - 'repo'       : to be able to read private repositories")
 	fmt.Println()
 
-	re, err := regexp.Compile(`^[a-zA-Z0-9]{40}$`)
-	if err != nil {
-		panic("regexp compile:" + err.Error())
-	}
+	re := regexp.MustCompile(`^[a-zA-Z0-9]{40}$`)
 
 	var login string
 

bridge/gitlab/config.go 🔗

@@ -183,10 +183,7 @@ func promptToken(baseUrl string) (*auth.Token, error) {
 	fmt.Println("'api' access scope: to be able to make api calls")
 	fmt.Println()
 
-	re, err := regexp.Compile(`^[a-zA-Z0-9\-\_]{20}$`)
-	if err != nil {
-		panic("regexp compile:" + err.Error())
-	}
+	re := regexp.MustCompile(`^[a-zA-Z0-9\-\_]{20}$`)
 
 	var login string
 

bridge/launchpad/config.go 🔗

@@ -91,10 +91,7 @@ func validateProject(project string) (bool, error) {
 
 // extract project name from url
 func splitURL(url string) (string, error) {
-	re, err := regexp.Compile(`launchpad\.net[\/:]([^\/]*[a-z]+)`)
-	if err != nil {
-		panic("regexp compile:" + err.Error())
-	}
+	re := regexp.MustCompile(`launchpad\.net[\/:]([^\/]*[a-z]+)`)
 
 	res := re.FindStringSubmatch(url)
 	if res == nil {