chore: formating
This commit is contained in:
		
							parent
							
								
									0111c08796
								
							
						
					
					
						commit
						26c57e9da8
					
				
							
								
								
									
										92
									
								
								datautils.go
									
									
									
									
									
								
							
							
						
						
									
										92
									
								
								datautils.go
									
									
									
									
									
								
							@ -23,36 +23,36 @@ var DEBUGLEVEL int
 | 
			
		||||
 | 
			
		||||
func LoadPath(path string) ([]byte,error) {
 | 
			
		||||
	content, err := ioutil.ReadFile(path)
 | 
			
		||||
  if err != nil {
 | 
			
		||||
		return nil,err
 | 
			
		||||
  }
 | 
			
		||||
	if err != nil {
 | 
			
		||||
			return nil,err
 | 
			
		||||
	}
 | 
			
		||||
	return content, nil
 | 
			
		||||
}
 | 
			
		||||
func DecoderFromFile(path string) (*yaml.Decoder, *os.File, error) {
 | 
			
		||||
	file, err := os.Open(path)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
	 	// log.Fatalf("open file error: %v", err)
 | 
			
		||||
	 	fmt.Printf("open file error: %v\n", err)
 | 
			
		||||
		fmt.Printf("open file error: %v\n", err)
 | 
			
		||||
		return nil,nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return yaml.NewDecoder(file), file, nil
 | 
			
		||||
}
 | 
			
		||||
func ExistsPathErr(path string) error {
 | 
			
		||||
  _, err := os.Stat(path)
 | 
			
		||||
  if errors.Is(err, os.ErrNotExist) {
 | 
			
		||||
	_, err := os.Stat(path)
 | 
			
		||||
	if errors.Is(err, os.ErrNotExist) {
 | 
			
		||||
		return err // errors.New("File not exists")
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
func ExistsPath(path string) bool {
 | 
			
		||||
  _, err := os.Stat(path)
 | 
			
		||||
  return !errors.Is(err, os.ErrNotExist)
 | 
			
		||||
	_, err := os.Stat(path)
 | 
			
		||||
	return !errors.Is(err, os.ErrNotExist)
 | 
			
		||||
}
 | 
			
		||||
func CheckDirPath(path string) error {
 | 
			
		||||
	if ! ExistsPath(path) {
 | 
			
		||||
		os.Mkdir(path, os.FileMode(0755))
 | 
			
		||||
		if err := ExistsPathErr(path); err != nil {
 | 
			
		||||
	    fmt.Printf("Error creating path %s: %v\n", path,err)
 | 
			
		||||
			fmt.Printf("Error creating path %s: %v\n", path,err)
 | 
			
		||||
			return err
 | 
			
		||||
		}	
 | 
			
		||||
	}
 | 
			
		||||
@ -62,20 +62,20 @@ func WriteData(data string, path string) error {
 | 
			
		||||
	//fmt.Printf("Write %s\n", path)
 | 
			
		||||
	f, err := os.Create(path)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
	  fmt.Printf("Error create %s: %v\n", path, err)	
 | 
			
		||||
		fmt.Printf("Error create %s: %v\n", path, err)	
 | 
			
		||||
    return err
 | 
			
		||||
	}
 | 
			
		||||
	w := bufio.NewWriter(f)
 | 
			
		||||
  n4, err := w.WriteString(data)
 | 
			
		||||
	n4, err := w.WriteString(data)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
	  fmt.Printf("Error writing %s: %v\n", path, err)	
 | 
			
		||||
		fmt.Printf("Error writing %s: %v\n", path, err)	
 | 
			
		||||
    return err
 | 
			
		||||
	}
 | 
			
		||||
	if DEBUGLEVEL > 0 {
 | 
			
		||||
    fmt.Printf("%s wrote %d bytes\n", path, n4)
 | 
			
		||||
	}
 | 
			
		||||
  w.Flush()
 | 
			
		||||
  return nil
 | 
			
		||||
	w.Flush()
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
func WriteAppendData(data string, path string) error {
 | 
			
		||||
	if ! ExistsPath(path) {
 | 
			
		||||
@ -83,19 +83,19 @@ func WriteAppendData(data string, path string) error {
 | 
			
		||||
	}
 | 
			
		||||
	file, err := os.OpenFile(path, os.O_WRONLY|os.O_APPEND, 0644)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
	  fmt.Printf("Error create %s: %v\n", path, err)	
 | 
			
		||||
		fmt.Printf("Error create %s: %v\n", path, err)	
 | 
			
		||||
    return err
 | 
			
		||||
	}
 | 
			
		||||
	defer file.Close()
 | 
			
		||||
  n4, err := file.WriteString(data)
 | 
			
		||||
	n4, err := file.WriteString(data)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
	  fmt.Printf("Error writing %s: %v\n", path, err)	
 | 
			
		||||
    return err
 | 
			
		||||
		fmt.Printf("Error writing %s: %v\n", path, err)	
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	if DEBUGLEVEL > 0 {
 | 
			
		||||
    fmt.Printf("%s wrote %d bytes\n", path, n4)
 | 
			
		||||
		fmt.Printf("%s wrote %d bytes\n", path, n4)
 | 
			
		||||
	}
 | 
			
		||||
  return nil
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
func ExecCommand(command string, args []string, bckg bool, quiet bool) (*exec.Cmd,string,error) {
 | 
			
		||||
	cmd := exec.Command(command, args...)
 | 
			
		||||
@ -106,11 +106,11 @@ func ExecCommand(command string, args []string, bckg bool, quiet bool) (*exec.Cm
 | 
			
		||||
	if bckg {
 | 
			
		||||
		err = cmd.Start()
 | 
			
		||||
	} else {
 | 
			
		||||
	  err = cmd.Run()
 | 
			
		||||
		err = cmd.Run()
 | 
			
		||||
	}
 | 
			
		||||
	if err != nil {
 | 
			
		||||
	  if !quiet {
 | 
			
		||||
	 		fmt.Printf("Error exec command %s: %#v\n", cmd,err)
 | 
			
		||||
		if !quiet {
 | 
			
		||||
			fmt.Printf("Error exec command %s: %#v\n", cmd,err)
 | 
			
		||||
		}
 | 
			
		||||
		return cmd,out.String(),err
 | 
			
		||||
	}
 | 
			
		||||
@ -131,7 +131,7 @@ func GitCommit(path string, file string, msg string, target string, bckg bool, q
 | 
			
		||||
	var err error
 | 
			
		||||
	var out string
 | 
			
		||||
	if cmd,out,err = ExecCommand("git",[]string{"-C",path,"add",file},bckg,quiet); err != nil {
 | 
			
		||||
	  fmt.Printf("Error git add %s: %s\n %#v\n", path,out,err)
 | 
			
		||||
		fmt.Printf("Error git add %s: %s\n %#v\n", path,out,err)
 | 
			
		||||
    //return err
 | 
			
		||||
	}
 | 
			
		||||
	if _,_,err := ExecCommand("git",[]string{"-C",path,"commit","-m",msg},bckg,quiet); err != nil {
 | 
			
		||||
@ -152,11 +152,11 @@ func GitCommit(path string, file string, msg string, target string, bckg bool, q
 | 
			
		||||
	if cmd,out,err = ExecCommand("git",[]string{"-C",path,"push",target},bckg,quiet); err != nil {
 | 
			
		||||
		return cmd,out,err
 | 
			
		||||
	}
 | 
			
		||||
  return cmd,out,nil
 | 
			
		||||
	return cmd,out,nil
 | 
			
		||||
}
 | 
			
		||||
func GetFileMatch(root string, extension string) []string {
 | 
			
		||||
	var listFiles[]string
 | 
			
		||||
  err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
 | 
			
		||||
		err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			fmt.Println(err)
 | 
			
		||||
			return nil
 | 
			
		||||
@ -165,7 +165,7 @@ func GetFileMatch(root string, extension string) []string {
 | 
			
		||||
			listFiles = append(listFiles, path)
 | 
			
		||||
		}
 | 
			
		||||
		return nil
 | 
			
		||||
  }) 
 | 
			
		||||
	}) 
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		fmt.Printf("No files found in %s: %v\n",root, err)
 | 
			
		||||
		return nil
 | 
			
		||||
@ -176,12 +176,12 @@ func GetFileMatch(root string, extension string) []string {
 | 
			
		||||
func gitGetWorktree(path string) (*git.Repository, *git.Worktree, error) {
 | 
			
		||||
	repo, err := git.PlainOpen(path)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
	  fmt.Printf("Error path %s: %v\n", path, err)	
 | 
			
		||||
		fmt.Printf("Error path %s: %v\n", path, err)	
 | 
			
		||||
    return nil,nil,err
 | 
			
		||||
	}
 | 
			
		||||
	worktree, err := repo.Worktree()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
	  fmt.Printf("Error worktree %s: %v\n", path, err)	
 | 
			
		||||
		fmt.Printf("Error worktree %s: %v\n", path, err)	
 | 
			
		||||
    return nil,nil,err
 | 
			
		||||
	}
 | 
			
		||||
	return repo,worktree,nil
 | 
			
		||||
@ -190,27 +190,27 @@ func gitPull(path string, name string) error {
 | 
			
		||||
	fmt.Printf("Git Pull: %#v\n", path)
 | 
			
		||||
	repo,worktree,err := gitGetWorktree(path)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
	  fmt.Printf("Error worktree %s: %v\n", path, err)	
 | 
			
		||||
    return err
 | 
			
		||||
		fmt.Printf("Error worktree %s: %v\n", path, err)	
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	err = worktree.Pull(&git.PullOptions{RemoteName: name})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
	  fmt.Printf("Error pull %s: %v\n", path, err)	
 | 
			
		||||
    return err
 | 
			
		||||
		fmt.Printf("Error pull %s: %v\n", path, err)	
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	if DEBUGLEVEL > 0 {
 | 
			
		||||
		// Print the latest commit that was just pulled
 | 
			
		||||
		ref, err := repo.Head()
 | 
			
		||||
	  if err != nil {
 | 
			
		||||
	    fmt.Printf("Error repo Head %s: %v\n", path, err)	
 | 
			
		||||
      return err
 | 
			
		||||
  	}
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			fmt.Printf("Error repo Head %s: %v\n", path, err)	
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		commit, err := repo.CommitObject(ref.Hash())
 | 
			
		||||
	  if err != nil {
 | 
			
		||||
	    fmt.Printf("Error commit object %s: %v\n", path, err)	
 | 
			
		||||
      return err
 | 
			
		||||
  	}
 | 
			
		||||
	  fmt.Println(commit)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			fmt.Printf("Error commit object %s: %v\n", path, err)	
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		fmt.Println(commit)
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}	
 | 
			
		||||
@ -218,7 +218,7 @@ func gitCommit(path string, file string, msg string, name string, email string,
 | 
			
		||||
	// Opens an already existing repository.
 | 
			
		||||
	repo,worktree,err := gitGetWorktree(path)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
	  fmt.Printf("Error worktree %s: %v\n", path, err)	
 | 
			
		||||
		fmt.Printf("Error worktree %s: %v\n", path, err)	
 | 
			
		||||
    return err
 | 
			
		||||
	}
 | 
			
		||||
	// Info("echo \"hello world!\" > example-git-file")
 | 
			
		||||
@ -227,8 +227,8 @@ func gitCommit(path string, file string, msg string, name string, email string,
 | 
			
		||||
	// Adds the new file to the staging area.
 | 
			
		||||
	_, err = worktree.Add(file)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
	  fmt.Printf("Error git add %s: %v\n", file, err)	
 | 
			
		||||
    return err
 | 
			
		||||
		fmt.Printf("Error git add %s: %v\n", file, err)	
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	fmt.Printf("git add %s\n",file)
 | 
			
		||||
	if DEBUGLEVEL > 0 {
 | 
			
		||||
@ -252,7 +252,7 @@ func gitCommit(path string, file string, msg string, name string, email string,
 | 
			
		||||
		},
 | 
			
		||||
	})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
	  fmt.Printf("Error git create commit %s: %v\n", file, err)	
 | 
			
		||||
		fmt.Printf("Error git create commit %s: %v\n", file, err)	
 | 
			
		||||
    return err
 | 
			
		||||
	}
 | 
			
		||||
	// Prints the current HEAD to verify that all worked well.
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user