summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitaly Minko <vitaly.minko@gmail.com>2018-11-06 17:22:12 +0300
committerVitaly Minko <vitaly.minko@gmail.com>2018-11-06 17:22:12 +0300
commitc4e516b5ee21d6a08bf0cdd81ad8bdee1775af2b (patch)
treee6f7af5fa9c067afe060543f6d7cb4f08906c05b
parente1be8978f6bada8bd4bb548bae277526cb4b8804 (diff)
Added godoc wrapper for generating API documentation.
-rw-r--r--docs/dscuss.mkd7
-rwxr-xr-xutils/benchmark_pow.sh2
-rwxr-xr-xutils/generate_docs.sh84
3 files changed, 92 insertions, 1 deletions
diff --git a/docs/dscuss.mkd b/docs/dscuss.mkd
index 9270649..cc2f873 100644
--- a/docs/dscuss.mkd
+++ b/docs/dscuss.mkd
@@ -87,6 +87,13 @@ Or use this command if you just want to run Dscuss for one time:
go run cmd/dscuss-cli/main.go
+API
+---
+
+API description generated by godoc is available [here][godoc].
+[godoc]: /storage/dscuss/godoc/
+
+
Progress of development
-----------------------
diff --git a/utils/benchmark_pow.sh b/utils/benchmark_pow.sh
index 2f564fa..267040d 100755
--- a/utils/benchmark_pow.sh
+++ b/utils/benchmark_pow.sh
@@ -3,7 +3,7 @@
# This file is used for running Proof-of-Work benchmarks, generating
# histograms and calculating average time to find the proof.
#
-# (c) 2018 Vitaly Minko <vitaly.minko@gmail.com>
+# Copyright (c) 2018 Vitaly Minko <vitaly.minko@gmail.com>
COUNT=10
BIT_NUM=16
diff --git a/utils/generate_docs.sh b/utils/generate_docs.sh
new file mode 100755
index 0000000..866255c
--- /dev/null
+++ b/utils/generate_docs.sh
@@ -0,0 +1,84 @@
+#!/bin/sh
+#
+# This file is used for generating documentation via godoc tool.
+# Usage is described in the source code below.
+#
+# Copyright (c) 2018 Vitaly Minko <vitaly.minko@gmail.com>
+
+EXCLUDED_DIRS="docs utils"
+STATIC_DIR="$GOPATH/src/golang.org/x/tools/godoc/static/"
+
+die() {
+ echo "Error: $1"
+ exit 1
+}
+
+generate_htmls() {
+ local package=$1
+ local target_dir=$2
+ local target_uri=$3
+
+ local excludes=""
+ for exclude in ${EXCLUDED_DIRS}; do
+ excludes="${excludes} -not -path '${exclude}' -not -path '${exclude}/*'"
+ done
+
+ mkdir -p ${target_dir} || die "failed to create directory ${target_dir}"
+ echo "Generating documentation for ${package}..."
+ godoc -url "/pkg/${package}/" > "${target_dir}/index.html" || \
+ die "failed to generate doc for ${package}"
+
+ local subpackages=$(cd ${GOPATH}/src/${package} && echo ${excludes} | xargs find * -type d)
+ for subpackage in ${subpackages}; do
+ local target="${target_dir}/${subpackage}"
+ mkdir -p ${target} || die "failed to create directory ${target}"
+ echo "Generating documentation for ${package}/${subpackage}..."
+ godoc -url "/pkg/${package}/${subpackage}" > "${target}/index.html" || \
+ die "failed to generate doc for ${package}/${subpackage}"
+ done
+
+ # Replace target URI
+ find ${target_dir} -name index.html -exec \
+ sed -i "s|/lib/godoc/|${target_uri}${target_dir}/|" {} \; || \
+ die "failed to replace target URI in a static"
+}
+
+copy_statics() {
+ local target_dir=$1
+ local target_uri=$2
+ local statics=`grep "${target_uri}${target_dir}" ${target_dir}/index.html | \
+ sed -n "s|.*${target_uri}${target_dir}\(.*\)\".*|\1|p"`
+ for static in ${statics}; do
+ cp ${STATIC_DIR}${static} ${target_dir} || die "failed to copy a static"
+ done
+}
+
+if [ $# -ne 3 ]
+then
+ cat >&2 << EOF
+Usage:
+ $0 <package> <target_dir> <host_prefix>
+where,
+ <package> is the root package to generate documentation for.
+ <target_dir> is the directory to put the result in.
+ <target_uri> is the URI where the result will be published.
+Example:
+ utils/generate_docs.sh vminko.org/dscuss godoc /storage/dscuss/
+EOF
+ exit 1
+fi
+
+PACKAGE=$1
+TARGET_DIR=$2
+TARGET_URI=$3
+
+if [ -z "${GOPATH}" ]; then
+ echo "\$GOPATH is not set." 1>&2
+fi
+
+if [ ! -d "${STATIC_DIR}" ]; then
+ echo "Static directory of the godoc tool not found: ${STATIC_DIR}." 1>&2
+fi
+
+generate_htmls ${PACKAGE} ${TARGET_DIR} ${TARGET_URI}
+copy_statics ${TARGET_DIR} ${TARGET_URI}