diff --git a/.gitignore b/.gitignore index f0715eb..3debfb7 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ mstored cmd/mstored/mstored cmd/mstorectl/mstorectl *.db +*.db-shm +*.db-wal diff --git a/Makefile.am b/Makefile.am index 757bed1..78f9f47 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5,7 +5,8 @@ GOFLAGS= -v sbin_PROGRAMS = mstored -mstored_SOURCES = cmd/mstored/mstored.go +mstored_SOURCES = cmd/mstored/main.go + mstored$(EXEEXT): $(mstored_SOURCES) env CGO_ENABLED=1 $(GO) build $(GOFLAGS) -o mstored$(EXEEXT) $(mstored_SOURCES) diff --git a/Makefile.in b/Makefile.in index e841248..349d8cf 100644 --- a/Makefile.in +++ b/Makefile.in @@ -99,7 +99,7 @@ DIST_COMMON = $(srcdir)/Makefile.am $(top_srcdir)/configure \ am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ configure.lineno config.status.lineno mkinstalldirs = $(install_sh) -d -CONFIG_CLEAN_FILES = +CONFIG_CLEAN_FILES = app/config/variant.go CONFIG_CLEAN_VPATH_FILES = am__installdirs = "$(DESTDIR)$(sbindir)" PROGRAMS = $(sbin_PROGRAMS) @@ -158,7 +158,8 @@ am__define_uniq_tagged_files = \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` AM_RECURSIVE_TARGETS = cscope -am__DIST_COMMON = $(srcdir)/Makefile.in config.guess config.sub \ +am__DIST_COMMON = $(srcdir)/Makefile.in \ + $(top_srcdir)/app/config/variant.go.in config.guess config.sub \ install-sh missing DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) distdir = $(PACKAGE)-$(VERSION) @@ -267,6 +268,13 @@ runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ +srv_confdir = @srv_confdir@ +srv_datadir = @srv_datadir@ +srv_devel_mode = @srv_devel_mode@ +srv_libdir = @srv_libdir@ +srv_logdir = @srv_logdir@ +srv_rundir = @srv_rundir@ +srv_sharedir = @srv_sharedir@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ @@ -274,7 +282,7 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ AUTOMAKE_OPTIONS = foreign no-dependencies no-installinfo GOFLAGS = -v -mstored_SOURCES = cmd/mstored/mstored.go +mstored_SOURCES = cmd/mstored/main.go CWD = $(shell pwd) all: all-am @@ -312,6 +320,8 @@ $(top_srcdir)/configure: $(am__configure_deps) $(ACLOCAL_M4): $(am__aclocal_m4_deps) $(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS) $(am__aclocal_m4_deps): +app/config/variant.go: $(top_builddir)/config.status $(top_srcdir)/app/config/variant.go.in + cd $(top_builddir) && $(SHELL) ./config.status $@ install-sbinPROGRAMS: $(sbin_PROGRAMS) @$(NORMAL_INSTALL) @list='$(sbin_PROGRAMS)'; test -n "$(sbindir)" || list=; \ @@ -719,6 +729,7 @@ uninstall-am: uninstall-sbinPROGRAMS .PRECIOUS: Makefile + mstored$(EXEEXT): $(mstored_SOURCES) env CGO_ENABLED=1 $(GO) build $(GOFLAGS) -o mstored$(EXEEXT) $(mstored_SOURCES) diff --git a/app/config/config.go b/app/config/config.go index ba60373..789b8e9 100644 --- a/app/config/config.go +++ b/app/config/config.go @@ -1,7 +1,17 @@ package config type Config struct { - Service Service `json:"service" yaml:"service"` + Service Service `json:"service" yaml:"service"` + Database Database `json:"database" yaml:"database"` +} + +type Service struct { + Address string `json:"address" yaml:"address"` + Port int64 `json:"port" yaml:"port"` +} + +type Database struct { + Basepath string `json:"basepath" yaml:"basepath"` } func NewConfig() (*Config, error) { @@ -11,10 +21,8 @@ func NewConfig() (*Config, error) { Address: "0.0.0.0", Port: 1025, }, + Database: Database{ + Basepath: datadir, + }, }, err } - -type Service struct { - Address string `json:"address" yaml:"address"` - Port int64 `json:"port" yaml:"port"` -} diff --git a/app/config/variant.go b/app/config/variant.go new file mode 100644 index 0000000..e6d4d37 --- /dev/null +++ b/app/config/variant.go @@ -0,0 +1,9 @@ +package config + +const ( + confdir = "/home/ziggi/Projects/mstore/etc/mstore" + rundir = "/home/ziggi/Projects/mstore/tmp/run" + logdir = "/home/ziggi/Projects/mstore/tmp/log" + datadir = "/home/ziggi/Projects/mstore/tmp/data" + version = "0.1.0" +) diff --git a/app/config/variant.go.in b/app/config/variant.go.in new file mode 100644 index 0000000..21466af --- /dev/null +++ b/app/config/variant.go.in @@ -0,0 +1,9 @@ +package config + +const ( + confdir = "@srv_confdir@" + rundir = "@srv_rundir@" + logdir = "@srv_logdir@" + datadir = "@srv_datadir@" + version = "@PACKAGE_VERSION@" +) diff --git a/app/descr/file.go b/app/descr/file.go index 76d821e..6baa720 100644 --- a/app/descr/file.go +++ b/app/descr/file.go @@ -1,14 +1,13 @@ package descr type File struct { - ID string `db:"id" json:"id,omitempty" yaml:"id,omitempty"` - Collection string `db:"collection" json:"collection,omitempty" yaml:"collection,omitempty"` - Name string `db:"name" json:"name,omitempty" yaml:"name,omitempty"` - Checksum string `db:"checksum" json:"checksum,omitempty" yaml:"checksum,omitempty"` - Size int64 `db:"size" json:"size,omitempty" yaml:"size,omitempty"` - CreatedAt string `db:"created_at" json:"createdAt,omitempty" yaml:"createdAt,omitempty"` - UpdatedAt string `db:"updated_at" json:"updatedAt,omitempty" yaml:"updatedAt,omitempty"` - CreatedBy string `db:"created_by" json:"createdBy,omitempty" yaml:"createdBy,omitempty"` - UpdatedBy string `db:"updated_by" json:"updatedBy,omitempty" yaml:"updatedBy,omitempty"` + ID string `db:"id" json:"id,omitempty" yaml:"id,omitempty"` + Collection string `db:"collection" json:"collection,omitempty" yaml:"collection,omitempty"` + Name string `db:"name" json:"name,omitempty" yaml:"name,omitempty"` + Checksum string `db:"checksum" json:"checksum,omitempty" yaml:"checksum,omitempty"` + Size int64 `db:"size" json:"size,omitempty" yaml:"size,omitempty"` + CreatedAt string `db:"created_at" json:"createdAt,omitempty" yaml:"createdAt,omitempty"` + UpdatedAt string `db:"updated_at" json:"updatedAt,omitempty" yaml:"updatedAt,omitempty"` + CreatedBy string `db:"created_by" json:"createdBy,omitempty" yaml:"createdBy,omitempty"` + UpdatedBy string `db:"updated_by" json:"updatedBy,omitempty" yaml:"updatedBy,omitempty"` } - diff --git a/app/handler/file.go b/app/handler/file.go index 492a05d..20d7d2e 100644 --- a/app/handler/file.go +++ b/app/handler/file.go @@ -14,8 +14,6 @@ func (hand *Handler) FileExists(rctx *router.Context) { } hand.logg.Debugf("filepath: %s", filepath) - - code, _, _ := hand.oper.FileExists(params) rctx.SetStatus(code) } diff --git a/app/maindb/file_test.go b/app/maindb/file_test.go index 6a25824..a972717 100644 --- a/app/maindb/file_test.go +++ b/app/maindb/file_test.go @@ -1,48 +1,46 @@ package maindb - - import ( - "testing" + "testing" - "mstore/app/descr" - "mstore/pkg/auxtool" - "mstore/pkg/auxuuid" + "mstore/app/descr" + "mstore/pkg/auxtool" + "mstore/pkg/auxuuid" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/require" ) func TestFile(t *testing.T) { - var err error + var err error - dbDir := t.TempDir() - db := NewDatabase(dbDir) + dbDir := t.TempDir() + db := NewDatabase(dbDir) - err = db.OpenDatabase() - require.NoError(t, err) + err = db.OpenDatabase() + require.NoError(t, err) - err = db.InitDatabase() - require.NoError(t, err) + err = db.InitDatabase() + require.NoError(t, err) - id := auxuuid.NewUUID() - timenow := auxtool.TimeNow() - creator := "some" - collection := "foo" - newFile := &descr.File{ - ID: id, - Collection: "foo" , - Name: "bare", - CreatedAt: timenow, - UpdatedAt: timenow, - CreatedBy: creator, - UpdatedBy: creator, - } + id := auxuuid.NewUUID() + timenow := auxtool.TimeNow() + creator := "some" + collection := "foo" + newFile := &descr.File{ + ID: id, + Collection: "foo", + Name: "bare", + CreatedAt: timenow, + UpdatedAt: timenow, + CreatedBy: creator, + UpdatedBy: creator, + } - err = db.InsertFile(newFile) - require.NoError(t, err) + err = db.InsertFile(newFile) + require.NoError(t, err) - files, err := db.ListFilesByCollection(collection) - require.NoError(t, err) - require.Equal(t, len(files), 1) - require.Equal(t, files[0].ID, id) + files, err := db.ListFilesByCollection(collection) + require.NoError(t, err) + require.Equal(t, len(files), 1) + require.Equal(t, files[0].ID, id) } diff --git a/app/maindb/maindb.go b/app/maindb/maindb.go index 4bb0296..14b3e24 100644 --- a/app/maindb/maindb.go +++ b/app/maindb/maindb.go @@ -10,7 +10,6 @@ import ( _ "github.com/mattn/go-sqlite3" ) - type Database struct { datapath string log *logger.Logger diff --git a/app/operator/file.go b/app/operator/file.go index cec8213..0a0df50 100644 --- a/app/operator/file.go +++ b/app/operator/file.go @@ -3,7 +3,7 @@ package operator import ( "io" "net/http" - "path" + //"path" ) // File exists @@ -17,8 +17,8 @@ type FileExistsResult struct{} func (oper *Operator) FileExists(param *FileExistsParams) (int, *FileExistsResult, error) { var err error - filename := path.Base(param.Filepath) - dirname := path.Dir(filepath) + //filename := path.Base(param.Filepath) + //dirname := path.Dir(filepath) res := &FileExistsResult{} code := http.StatusOK diff --git a/app/operator/operator.go b/app/operator/operator.go index 692b1df..535d190 100644 --- a/app/operator/operator.go +++ b/app/operator/operator.go @@ -5,17 +5,17 @@ import ( ) type OperatorParams struct { - MainDB *database.Database + MainDB *maindb.Database } type Operator struct { - maindb *main.Database + maindb *maindb.Database } func NewOperator(params *OperatorParams) (*Operator, error) { var err error oper := &Operator{ - db: params.MainDB, + maindb: params.MainDB, } return oper, err } diff --git a/app/server/server.go b/app/server/server.go index 08d5d95..ae7e1d3 100644 --- a/app/server/server.go +++ b/app/server/server.go @@ -12,19 +12,21 @@ import ( "syscall" //"time" - "mstore/app/database" + "mstore/app/config" "mstore/app/handler" "mstore/app/logger" + "mstore/app/maindb" "mstore/app/operator" "mstore/app/service" ) type Server struct { - oper *operator.Operator - svc *service.Service - db *database.Database - hand *handler.Handler - logg *logger.Logger + conf *config.Config + oper *operator.Operator + svc *service.Service + maindb *maindb.Database + hand *handler.Handler + logg *logger.Logger } func NewServer() (*Server, error) { @@ -41,21 +43,38 @@ func (srv *Server) Handler() *handler.Handler { func (srv *Server) Configure() error { var err error srv.logg.Infof("Server configure") + srv.conf, err = config.NewConfig() + if err != nil { + return err + } + return err } func (srv *Server) Build() error { var err error srv.logg.Infof("Server build") + // Database create - databaseParams := &database.DatabaseParams{} - srv.db, err = database.NewDatabase(databaseParams) + dbdir := srv.conf.Database.Basepath + err = os.MkdirAll(srv.conf.Database.Basepath, 0750) if err != nil { return err } + + maindb := maindb.NewDatabase(dbdir) + err = maindb.OpenDatabase() + if err != nil { + return err + } + err = maindb.InitDatabase() + if err != nil { + return err + } + // Operator create operatorParams := &operator.OperatorParams{ - Database: srv.db, + MainDB: srv.maindb, } srv.oper, err = operator.NewOperator(operatorParams) if err != nil { diff --git a/configure b/configure index a24dc70..7422bfe 100755 --- a/configure +++ b/configure @@ -615,6 +615,13 @@ PACKAGE_URL='' ac_default_prefix=/usr/local ac_subst_vars='LTLIBOBJS LIBOBJS +srv_datadir +srv_libdir +srv_sharedir +srv_rundir +srv_logdir +srv_confdir +srv_devel_mode SYSTEMD_FALSE SYSTEMD_TRUE LINUX_OS_FALSE @@ -710,6 +717,13 @@ ac_subst_files='' ac_user_opts=' enable_option_checking enable_silent_rules +enable_devel_mode +with_confdir +with_logdir +with_rundir +with_sharedir +with_libdir +with_datadir ' ac_precious_vars='build_alias host_alias @@ -1343,6 +1357,18 @@ Optional Features: --enable-FEATURE[=ARG] include FEATURE [ARG=yes] --enable-silent-rules less verbose build output (undo: "make V=1") --disable-silent-rules verbose build output (undo: "make V=0") + --enable-devel-mode Enable developmend mode + +Optional Packages: + --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] + --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) + --with-confdir=PATH set configuration dir to PATH (default: + $SRV_CONFDIR) + --with-logdir=PATH set path for logdir (default: $SRV_LOGDIR) + --with-rundir=PATH set path for rundir (default: $SRV_RUNDIR) + --with-sharedir=PATH set share directory (default: $SRV_SHAREDIR) + --with-libdir=PATH set lib directory (default: $SRV_LIBDIR) + --with-datadir=PATH set path for datadir (default: $SRV_DATADIR) Report bugs to the package provider. _ACEOF @@ -3062,7 +3088,263 @@ fi fi -ac_config_files="$ac_config_files Makefile" + +test "x$prefix" == "xNONE" && prefix=$ac_default_prefix +test "x$libexecdir" == "xNONE" && libexecdir=${prefix}/lib + + + +# Check whether --enable-devel-mode was given. +if test ${enable_devel_mode+y} +then : + enableval=$enable_devel_mode; +fi + + + + +printf "%s\n" "#define srv_devel_mode \"false\"" >>confdefs.h + +srv_devel_mode="false" + + +if test "x$enable_devel_mode" = "xyes" +then : + + SRCDIR=`pwd` + enable_devel_mode=yes + +fi + + +SRV_CONFDIR="${prefix}/etc/${PACKAGE}" + + +# Check whether --with-confdir was given. +if test ${with_confdir+y} +then : + withval=$with_confdir; if test ! -z "$withval" ; then + case $withval in + /*) + SRV_CONFDIR="$withval" + ;; + *) + as_fn_error $? "You must specify an absolute path to --with-confdir=PATH" "$LINENO" 5 + ;; + esac + fi +fi + + + +if test "x$enable_devel_mode" = "xyes" +then : + + SRV_CONFDIR="${SRCDIR}/etc/${PACKAGE}" + sysconfdir="${SRCDIR}/etc/${PACKAGE}" + +else $as_nop + + test "x$SRV_CONFDIR" == "x/usr/etc/${PACKAGE}" && SRV_CONFDIR="/etc/${PACKAGE}" + test "x$prefix" == "x/usr" && sysconfdir="/etc" + +fi + + +printf "%s\n" "#define SRV_CONFDIR \"$SRV_CONFDIR\"" >>confdefs.h + +srv_confdir="$SRV_CONFDIR" + + +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: srv_confdir set as ${SRV_CONFDIR}" >&5 +printf "%s\n" "$as_me: srv_confdir set as ${SRV_CONFDIR}" >&6;} + + +SRV_LOGDIR="/var/log/${PACKAGE}" + + +# Check whether --with-logdir was given. +if test ${with_logdir+y} +then : + withval=$with_logdir; if test ! -z "$withval" ; then + case $withval in + /*) + SRV_LOGDIR="$withval" + ;; + *) + as_fn_error $? "You must specify an absolute path to --with-logdir=PATH" "$LINENO" 5 + ;; + esac + fi +fi + + +if test "x$enable_devel_mode" = "xyes" +then : + + SRV_LOGDIR="${SRCDIR}/tmp/log" + +fi + + +printf "%s\n" "#define SRV_LOGDIR \"$SRV_LOGDIR\"" >>confdefs.h + +srv_logdir="$SRV_LOGDIR" + + +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: srv_logdir set as ${SRV_LOGDIR}" >&5 +printf "%s\n" "$as_me: srv_logdir set as ${SRV_LOGDIR}" >&6;} + + +SRV_RUNDIR="/var/run/${PACKAGE}" + + +# Check whether --with-rundir was given. +if test ${with_rundir+y} +then : + withval=$with_rundir; if test ! -z "$withval" ; then + case $withval in + /*) + SRV_RUNDIR="$withval" + ;; + *) + as_fn_error $? "You must specify an absolute path to --with-rundir=PATH" "$LINENO" 5 + ;; + esac + fi +fi + + +if test "x$enable_devel_mode" = "xyes" +then : + + SRV_RUNDIR="${SRCDIR}/tmp/run" + +fi + + + +printf "%s\n" "#define SRV_RUNDIR \"$SRV_RUNDIR\"" >>confdefs.h + +srv_rundir="$SRV_RUNDIR" + + +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: srv_rundir set as ${SRV_RUNDIR}" >&5 +printf "%s\n" "$as_me: srv_rundir set as ${SRV_RUNDIR}" >&6;} + + +SRV_SHAREDIR="${prefix}/share/$PACKAGE" + + +# Check whether --with-sharedir was given. +if test ${with_sharedir+y} +then : + withval=$with_sharedir; if test ! -z "$with_sharedir" ; then + case $with_sharedir in + /*) + SRV_SHAREDIR="$withval" + ;; + *) + as_fn_error $? "You must specify an absolute path to --with-sharedir=PATH" "$LINENO" 5 + ;; + esac + fi +fi + + +if test "x$enable_devel_mode" = "xyes" +then : + + SRV_SHAREDIR="${SRCDIR}/share" + +fi + + + +printf "%s\n" "#define SRV_SHAREDIR \"$SRV_SHAREDIR\"" >>confdefs.h + +srv_sharedir="$SRV_SHAREDIR" + + +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: srv_sharedir set as ${SRV_SHAREDIR}" >&5 +printf "%s\n" "$as_me: srv_sharedir set as ${SRV_SHAREDIR}" >&6;} + + +SRV_LIBDIR="${prefix}/lib/$PACKAGE" + + +# Check whether --with-libdir was given. +if test ${with_libdir+y} +then : + withval=$with_libdir; if test ! -z "$withval" ; then + case $withval in + /*) + SRV_LIBDIR="$withval" + ;; + *) + as_fn_error $? "You must specify an absolute path to --with-libdir=PATH" "$LINENO" 5 + ;; + esac + fi +fi + + +if test "x$enable_devel_mode" = "xyes" +then : + + SRV_LIBDIR="${SRCDIR}/sysagent" + +fi + + +printf "%s\n" "#define SRV_LIBDIR \"$SRV_LIBDIR\"" >>confdefs.h + +srv_libdir="$SRV_LIBDIR" + + +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: srv_libdir set as ${SRV_LIBDIR}" >&5 +printf "%s\n" "$as_me: srv_libdir set as ${SRV_LIBDIR}" >&6;} + + + +SRV_DATADIR="/var/data/${PACKAGE}" + + +# Check whether --with-datadir was given. +if test ${with_datadir+y} +then : + withval=$with_datadir; if test ! -z "$withval" ; then + case $withval in + /*) + SRV_DATADIR="$withval" + ;; + *) + as_fn_error $? "You must specify an absolute path to --with-datadir=PATH" "$LINENO" 5 + ;; + esac + fi +fi + + +if test "x$enable_devel_mode" = "xyes" +then : + + SRV_DATADIR="${SRCDIR}/tmp/data" + +fi + + +printf "%s\n" "#define SRV_DATADIR \"$SRV_DATADIR\"" >>confdefs.h + +srv_datadir="$SRV_DATADIR" + + +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: srv_datadir set as ${SRV_DATADIR}" >&5 +printf "%s\n" "$as_me: srv_datadir set as ${SRV_DATADIR}" >&6;} + + + +ac_config_files="$ac_config_files Makefile app/config/variant.go" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -3801,6 +4083,7 @@ for ac_config_target in $ac_config_targets do case $ac_config_target in "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; + "app/config/variant.go") CONFIG_FILES="$CONFIG_FILES app/config/variant.go" ;; *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; esac diff --git a/configure.ac b/configure.ac index df1a119..034c3c3 100644 --- a/configure.ac +++ b/configure.ac @@ -47,7 +47,194 @@ if test -d /lib/systemd/system; then AM_CONDITIONAL(SYSTEMD, true) fi + +test "x$prefix" == "xNONE" && prefix=$ac_default_prefix +test "x$libexecdir" == "xNONE" && libexecdir=${prefix}/lib + + +dnl -------------------------------------------------------------------------------------- + +AC_ARG_ENABLE([devel-mode], + AS_HELP_STRING([--enable-devel-mode], [Enable developmend mode])) + + +AC_DEFINE_UNQUOTED(srv_devel_mode, "false", [developmend mode]) +AC_SUBST(srv_devel_mode, "false") + +AS_IF([test "x$enable_devel_mode" = "xyes"], [ + SRCDIR=`pwd` + enable_devel_mode=yes +]) + +dnl -------------------------------------------------------------------------------------- + +SRV_CONFDIR="${prefix}/etc/${PACKAGE}" + +AC_ARG_WITH(confdir, + AS_HELP_STRING([--with-confdir=PATH],[set configuration dir to PATH (default: $SRV_CONFDIR)]), + [ if test ! -z "$withval" ; then + case $withval in + /*) + SRV_CONFDIR="$withval" + ;; + *) + AC_MSG_ERROR(You must specify an absolute path to --with-confdir=PATH) + ;; + esac + fi ]) + + +AS_IF([test "x$enable_devel_mode" = "xyes"], [ + SRV_CONFDIR="${SRCDIR}/etc/${PACKAGE}" + sysconfdir="${SRCDIR}/etc/${PACKAGE}" +], [ + test "x$SRV_CONFDIR" == "x/usr/etc/${PACKAGE}" && SRV_CONFDIR="/etc/${PACKAGE}" + test "x$prefix" == "x/usr" && sysconfdir="/etc" +]) + +AC_DEFINE_UNQUOTED(SRV_CONFDIR, "$SRV_CONFDIR", [location of configuration files for ${PACKAGE}]) +AC_SUBST(srv_confdir, "$SRV_CONFDIR") + +AC_MSG_NOTICE(srv_confdir set as ${SRV_CONFDIR}) + +dnl -------------------------------------------------------------------------------------- + +SRV_LOGDIR="/var/log/${PACKAGE}" + +AC_ARG_WITH(logdir, + AS_HELP_STRING([--with-logdir=PATH],[set path for logdir (default: $SRV_LOGDIR)]), + [ if test ! -z "$withval" ; then + case $withval in + /*) + SRV_LOGDIR="$withval" + ;; + *) + AC_MSG_ERROR(You must specify an absolute path to --with-logdir=PATH) + ;; + esac + fi]) + +AS_IF([test "x$enable_devel_mode" = "xyes"], [ + SRV_LOGDIR="${SRCDIR}/tmp/log" +]) + +AC_DEFINE_UNQUOTED(SRV_LOGDIR, "$SRV_LOGDIR", [location of ${PACKAGE} logdir]) +AC_SUBST(srv_logdir, "$SRV_LOGDIR") + +AC_MSG_NOTICE(srv_logdir set as ${SRV_LOGDIR}) + +dnl -------------------------------------------------------------------------------------- + +SRV_RUNDIR="/var/run/${PACKAGE}" + +AC_ARG_WITH(rundir, + AS_HELP_STRING([--with-rundir=PATH],[set path for rundir (default: $SRV_RUNDIR)]), + [ if test ! -z "$withval" ; then + case $withval in + /*) + SRV_RUNDIR="$withval" + ;; + *) + AC_MSG_ERROR(You must specify an absolute path to --with-rundir=PATH) + ;; + esac + fi ]) + +AS_IF([test "x$enable_devel_mode" = "xyes"], [ + SRV_RUNDIR="${SRCDIR}/tmp/run" +]) + + +AC_DEFINE_UNQUOTED(SRV_RUNDIR, "$SRV_RUNDIR", [location of rundir]) +AC_SUBST(srv_rundir, "$SRV_RUNDIR") + +AC_MSG_NOTICE(srv_rundir set as ${SRV_RUNDIR}) + +dnl -------------------------------------------------------------------------------------- + +SRV_SHAREDIR="${prefix}/share/$PACKAGE" + +AC_ARG_WITH(sharedir, + AS_HELP_STRING([--with-sharedir=PATH],[set share directory (default: $SRV_SHAREDIR)]), + [ if test ! -z "$with_sharedir" ; then + case $with_sharedir in + /*) + SRV_SHAREDIR="$withval" + ;; + *) + AC_MSG_ERROR(You must specify an absolute path to --with-sharedir=PATH) + ;; + esac + fi ]) + +AS_IF([test "x$enable_devel_mode" = "xyes"], [ + SRV_SHAREDIR="${SRCDIR}/share" +]) + + +AC_DEFINE_UNQUOTED(SRV_SHAREDIR, "$SRV_SHAREDIR", [location of share dir]) +AC_SUBST(srv_sharedir, "$SRV_SHAREDIR") + +AC_MSG_NOTICE(srv_sharedir set as ${SRV_SHAREDIR}) + +dnl -------------------------------------------------------------------------------------- + +SRV_LIBDIR="${prefix}/lib/$PACKAGE" + +AC_ARG_WITH(libdir, + AS_HELP_STRING([--with-libdir=PATH],[set lib directory (default: $SRV_LIBDIR)]), + [ if test ! -z "$withval" ; then + case $withval in + /*) + SRV_LIBDIR="$withval" + ;; + *) + AC_MSG_ERROR(You must specify an absolute path to --with-libdir=PATH) + ;; + esac + fi ]) + +AS_IF([test "x$enable_devel_mode" = "xyes"], [ + SRV_LIBDIR="${SRCDIR}/sysagent" +]) + +AC_DEFINE_UNQUOTED(SRV_LIBDIR, "$SRV_LIBDIR", [location of lib dir]) +AC_SUBST(srv_libdir, "$SRV_LIBDIR") + +AC_MSG_NOTICE(srv_libdir set as ${SRV_LIBDIR}) + +dnl -------------------------------------------------------------------------------------- + + +SRV_DATADIR="/var/data/${PACKAGE}" + +AC_ARG_WITH(datadir, + AS_HELP_STRING([--with-datadir=PATH],[set path for datadir (default: $SRV_DATADIR)]), + [ if test ! -z "$withval" ; then + case $withval in + /*) + SRV_DATADIR="$withval" + ;; + *) + AC_MSG_ERROR(You must specify an absolute path to --with-datadir=PATH) + ;; + esac + fi]) + +AS_IF([test "x$enable_devel_mode" = "xyes"], [ + SRV_DATADIR="${SRCDIR}/tmp/data" +]) + +AC_DEFINE_UNQUOTED(SRV_DATADIR, "$SRV_DATADIR", [location of ${PACKAGE} datadir]) +AC_SUBST(srv_datadir, "$SRV_DATADIR") + +AC_MSG_NOTICE(srv_datadir set as ${SRV_DATADIR}) + +dnl -------------------------------------------------------------------------------------- + + AC_CONFIG_FILES([ Makefile +app/config/variant.go ]) AC_OUTPUT diff --git a/pkg/auxtool/unixnow.go b/pkg/auxtool/unixnow.go index 7259dbf..2c7371d 100644 --- a/pkg/auxtool/unixnow.go +++ b/pkg/auxtool/unixnow.go @@ -1,10 +1,10 @@ package auxtool import ( - "time" + "time" ) func TimeNow() string { - return time.Now().Format(time.RFC3339) + return time.Now().Format(time.RFC3339) } diff --git a/pkg/auxuuid/uuid.go b/pkg/auxuuid/uuid.go index ebccb21..c210837 100644 --- a/pkg/auxuuid/uuid.go +++ b/pkg/auxuuid/uuid.go @@ -1,11 +1,11 @@ package auxuuid import ( - "github.com/google/uuid" + "github.com/google/uuid" ) const ZeroUUID = "00000000-0000-0000-0000-000000000000" func NewUUID() string { - return uuid.New().String() + return uuid.New().String() } diff --git a/pkg/client/client.go b/pkg/client/client.go index eadb2ac..a5e0a10 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -1,10 +1,9 @@ package client - type Client struct { } func (cli *Client) FileExists(path string) (bool, error) { - //reqPath = fmt.Sprintf("/v3/api/file/%s", path) - //request, err := http.NewRequest("HEAD", reqPath, nil) + //reqPath = fmt.Sprintf("/v3/api/file/%s", path) + //request, err := http.NewRequest("HEAD", reqPath, nil) } diff --git a/test/svc_test.go b/test/svc_test.go index a9b3ee3..ef13b83 100644 --- a/test/svc_test.go +++ b/test/svc_test.go @@ -9,13 +9,12 @@ import ( "mstore/app/router" "mstore/app/server" - "mstore/app/service" - //"mstore/pkg/client" "github.com/stretchr/testify/require" ) -func TestFileExists(t *testing.T) { +func MakeServer(t *testing.T) *server.Server { + var err error srv, err := server.NewServer() require.NoError(t, err) @@ -26,6 +25,15 @@ func TestFileExists(t *testing.T) { err = srv.Build() require.NoError(t, err) + return srv +} + +func TestFileExists(t *testing.T) { + var err error + + srv := MakeServer(t) + require.NotNil(t, srv) + reqPath := `/v3/api/file/foo/bare` routePath := `/v3/api/file/{filepath}` @@ -44,28 +52,24 @@ func TestFileExists(t *testing.T) { fmt.Printf("Response code: %d\n", recorder.Code) - //bodyReader := recorder.Body - //bodyBytes, err := io.ReadAll(bodyReader) + bodyReader := recorder.Body + bodyBytes, err := io.ReadAll(bodyReader) - //fmt.Printf("Response body: %s\n", string(bodyBytes)) + fmt.Printf("Response body: %s\n", string(bodyBytes)) } -func xxxTestServiceHello(t *testing.T) { +func TestServiceHello(t *testing.T) { var err error - srv, err := server.NewServer() - require.NoError(t, err) - err = srv.Configure() - require.NoError(t, err) + srv := MakeServer(t) + require.NotNil(t, srv) - err = srv.Build() - require.NoError(t, err) - - reqPath := service.ServiceHelloPath + reqPath := "/service/hello" + routePath := "/service/hello" rout := router.NewRouter() hand := srv.Handler() - rout.Get(reqPath, hand.SendHello) + rout.Get(routePath, hand.SendHello) request, err := http.NewRequest("GET", reqPath, nil) require.NoError(t, err)