zoukankan      html  css  js  c++  java
  • 如何快速查看一个golang项目的总体结构?

    脚本如下

    #!/usr/bin/env bash
    [[ -n $DEBUG ]] && set -x
    set -ou pipefail
    
    useage(){
      cat <<"EOF"
    USAGE:
        gop.sh SRCPATH
    EOF
    }
    
    exit_err() {
       echo >&2 "${1}"
       exit 1
    }
    
    if [ $# -ne 1 ];then
        useage
        exit
    fi
    
    SRCPATH=$1
    if [ ! -d  "${SRCPATH}" ];then
        echo "${SRCPATH} is not a dir"
        exit
    fi
    
    cd "${SRCPATH}" || return
    
    red='33[0;31m'
    plain='33[0m'
    
    info(){
        echo -ne "
    ${red}$1:${plain}
    "
    }
    
    filenovendor(){
        find . -type f -name "$1" -not -path "./vendor/*"
    }
    
    grepnovendor(){
        grep --exclude-dir=vendor --include="$1" -Por "$2"
    }
    
    grepnovendorz(){
        grep --exclude-dir=vendor --include="$1" -Porz "$2"
    }
    
    info "仓库统计"
    git shortlog --numbered --summary .
    
    info "目录结构"
    tree -d -I vendor
    
    info "导入的包"
    grepnovendorz "*.go" "(?<=imports)(([^()]|(?R))*(?=))"
    
    info "定义的包"
    grepnovendor "*.go" "(?<=^packages).*$"
    
    info "注解信息"
    grepnovendor "*.go" "^//s*@.*$"
    
    # info "注释信息"
    # grepnovendor "*.go" "^//s*[^@]*$"
    
    info "路径信息"
    grepnovendor "*.go" '"/[^(|/")]+/*[^(")]*"'
    
    info "main.go"
    filenovendor "main.go"
    
    info "json"
    filenovendor "*.json"
    
    info "xml"
    filenovendor "*.xml"
    
    info "proto"
    filenovendor "*.proto"
    
    info "sql"
    filenovendor "*.sql"
    
    info "命令脚本"
    filenovendor "*.sh"
    
    info "构建文件"
    filenovendor "Makefile*"
    
    info "构建目标"
    grepnovendor "Makefile*" "^S*(?=:)"
    
    info "容器构建"
    filenovendor "Dockerfile*"
    
    info "基础容器"
    grepnovendor "Dockerfile*"  "(?<=FROMs).*$"
    
    info "容器镜像"
    grepnovendor "*.yaml"  "(?<=image:s).*$"
    grepnovendor "*.yml"  "(?<=image:s).*$"
    
    info "yml"
    filenovendor "*.yml"
    
    info "yaml"
    filenovendor "*.yaml"
    
    info "markdown"
    filenovendor "*.md"
    
    cd - || return
    
    
    gop ./projectdir/
    
  • 相关阅读:
    刷皇室成员
    python 2.7中matplotlib的所有版本
    Linux命令使用时路径存在空格、特殊符号
    路径名太长导致无法读取文件
    谷歌浏览器打包插件
    Upload 上载新生
    Linux的终端(base),进入base环境
    Ubuntu16.04系统语言设置为中文以及搜狗输入法的安装
    R语言3D图导出矢量图有bug
    将本地文件复制到hadoop文件系统
  • 原文地址:https://www.cnblogs.com/futuretea/p/11999815.html
Copyright © 2011-2022 走看看