This commit is contained in:
Олег Бородин
2024-07-03 00:28:42 +02:00
parent ada2a49a64
commit 1cc8b577cd
13 changed files with 178 additions and 37 deletions

3
.gitignore vendored
View File

@@ -5,5 +5,6 @@ Makefile
*.lineno
*.tmp
tmp.*
hamloggerd
xhamloggerd
autom4te.cache/
node-modules

View File

@@ -1,3 +1,4 @@
AUTOMAKE_OPTIONS = foreign no-dependencies no-installinfo
SUFFIXES = .go

View File

@@ -202,7 +202,6 @@ CP = @CP@
CSCOPE = @CSCOPE@
CTAGS = @CTAGS@
CYGPATH_W = @CYGPATH_W@
DBUILDPACKAGE = @DBUILDPACKAGE@
DEFS = @DEFS@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
@@ -220,6 +219,7 @@ LIBS = @LIBS@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
NODE = @NODE@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
@@ -233,6 +233,7 @@ SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
VERSION = @VERSION@
YARN = @YARN@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
abs_top_builddir = @abs_top_builddir@

83
configure vendored
View File

@@ -640,7 +640,8 @@ build_os
build_vendor
build_cpu
build
DBUILDPACKAGE
NODE
YARN
CP
GO
go
@@ -2722,19 +2723,19 @@ if test -z "$CP"; then
as_fn_error $? "Requested program cp not found" "$LINENO" 5
fi
for ac_prog in dpkg-buildpackage true
for ac_prog in yarn npm
do
# Extract the first word of "$ac_prog", so it can be a program name with args.
set dummy $ac_prog; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_path_DBUILDPACKAGE+y}
if test ${ac_cv_path_YARN+y}
then :
printf %s "(cached) " >&6
else $as_nop
case $DBUILDPACKAGE in
case $YARN in
[\\/]* | ?:[\\/]*)
ac_cv_path_DBUILDPACKAGE="$DBUILDPACKAGE" # Let the user override the test with a path.
ac_cv_path_YARN="$YARN" # Let the user override the test with a path.
;;
*)
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -2748,7 +2749,7 @@ do
esac
for ac_exec_ext in '' $ac_executable_extensions; do
if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
ac_cv_path_DBUILDPACKAGE="$as_dir$ac_word$ac_exec_ext"
ac_cv_path_YARN="$as_dir$ac_word$ac_exec_ext"
printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
break 2
fi
@@ -2759,19 +2760,76 @@ IFS=$as_save_IFS
;;
esac
fi
DBUILDPACKAGE=$ac_cv_path_DBUILDPACKAGE
if test -n "$DBUILDPACKAGE"; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $DBUILDPACKAGE" >&5
printf "%s\n" "$DBUILDPACKAGE" >&6; }
YARN=$ac_cv_path_YARN
if test -n "$YARN"; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $YARN" >&5
printf "%s\n" "$YARN" >&6; }
else
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi
test -n "$DBUILDPACKAGE" && break
test -n "$YARN" && break
done
if test -z "$YARN"; then
as_fn_error $? "Requested program yarn not found" "$LINENO" 5
fi
for ac_prog in node
do
# Extract the first word of "$ac_prog", so it can be a program name with args.
set dummy $ac_prog; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_path_NODE+y}
then :
printf %s "(cached) " >&6
else $as_nop
case $NODE in
[\\/]* | ?:[\\/]*)
ac_cv_path_NODE="$NODE" # Let the user override the test with a path.
;;
*)
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
case $as_dir in #(((
'') as_dir=./ ;;
*/) ;;
*) as_dir=$as_dir/ ;;
esac
for ac_exec_ext in '' $ac_executable_extensions; do
if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
ac_cv_path_NODE="$as_dir$ac_word$ac_exec_ext"
printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
break 2
fi
done
done
IFS=$as_save_IFS
;;
esac
fi
NODE=$ac_cv_path_NODE
if test -n "$NODE"; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $NODE" >&5
printf "%s\n" "$NODE" >&6; }
else
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi
test -n "$NODE" && break
done
if test -z "$NODE"; then
as_fn_error $? "Requested program node not found" "$LINENO" 5
fi
@@ -3208,7 +3266,7 @@ fi
srv_name="$PACKAGE"
ac_config_files="$ac_config_files Makefile internal/config/path.go initrc/hamloggerd.service initrc/hamloggerd"
ac_config_files="$ac_config_files Makefile internal/config/path.go initrc/hamloggerd.service initrc/hamloggerd front/Makefile"
cat >confcache <<\_ACEOF
# This file is a shell script that caches the results of configure
@@ -3958,6 +4016,7 @@ do
"internal/config/path.go") CONFIG_FILES="$CONFIG_FILES internal/config/path.go" ;;
"initrc/hamloggerd.service") CONFIG_FILES="$CONFIG_FILES initrc/hamloggerd.service" ;;
"initrc/hamloggerd") CONFIG_FILES="$CONFIG_FILES initrc/hamloggerd" ;;
"front/Makefile") CONFIG_FILES="$CONFIG_FILES front/Makefile" ;;
*) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
esac

View File

@@ -16,7 +16,15 @@ if test -z "$CP"; then
AC_MSG_ERROR([Requested program cp not found])
fi
AC_PATH_PROGS([DBUILDPACKAGE],[dpkg-buildpackage true])
AC_PATH_PROGS([YARN],[yarn npm])
if test -z "$YARN"; then
AC_MSG_ERROR([Requested program yarn not found])
fi
AC_PATH_PROGS([NODE],[node])
if test -z "$NODE"; then
AC_MSG_ERROR([Requested program node not found])
fi
AC_PROG_INSTALL
@@ -252,5 +260,6 @@ Makefile
internal/config/path.go
initrc/hamloggerd.service
initrc/hamloggerd
front/Makefile
])
AC_OUTPUT

View File

@@ -17,7 +17,7 @@ const (
defaultKeyFile = "hamlogger.key"
applicationName = "hamlogger"
defaultPort int = 20120
defaultPort int = 8081
)
var (
@@ -36,6 +36,7 @@ type Config struct {
LogPath string `json:"logfile" yaml:"logfile"`
RunPath string `json:"runfile" yaml:"runfile"`
DataPath string `json:"datadir" yaml:"datadir"`
SharePath string `json:"sharedir" yaml:"sharedir"`
Daemon bool `json:"daemon" yaml:"daemon"`
CertPath string `json:"certPath" yaml:"certPath"`
KeyPath string `json:"keyPath" yaml:"keyPath"`
@@ -51,6 +52,7 @@ func NewConfig() *Config {
Hostname: defaultHostname,
Build: defaultBuild,
DataPath: datadirPath,
SharePath: sharedirPath,
Daemon: false,
Debug: false,
}
@@ -121,7 +123,7 @@ func (conf *Config) ReadOpts() error {
func (conf *Config) Postproc() error {
var err error
if conf.X509Cert == "" || conf.X509Key == "" {
certBytes, keyBytes, err := aux509.CreateX509SelfSignedCert(conf.Hostname)
certBytes, keyBytes, err := aux509.CreateX509Cert(conf.Hostname)
if err != nil {
return err
}

View File

@@ -6,5 +6,7 @@ const (
rundirPath = "@srv_rundir@"
logdirPath = "@srv_logdir@"
datadirPath = "@srv_datadir@"
sharedirPath = "@srv_sharedir@"
)

View File

@@ -7,21 +7,24 @@ import (
type HandlerConfig struct {
Datadir string
Sharedir string
Database *database.Database
}
type Handler struct {
log *logger.Logger
db *database.Database
datadir string
log *logger.Logger
db *database.Database
datadir string
sharedir string
}
func NewHandler(conf *HandlerConfig) (*Handler, error) {
var err error
hand := &Handler{
datadir: conf.Datadir,
db: conf.Database,
log: logger.NewLogger("handler"),
datadir: conf.Datadir,
sharedir: conf.Sharedir,
db: conf.Database,
log: logger.NewLogger("handler"),
}
return hand, err
}

View File

@@ -1,15 +1,47 @@
package handler
import (
"io"
"os"
"path/filepath"
"fmt"
"hamlogger/internal/router"
)
type HelloParams struct{}
type HelloResult struct{}
func (hand *Handler) Hello(ctx *router.Context) {
func (hand *Handler) GetHello(ctx *router.Context) {
var err error
res := &HelloResult{}
hand.SendResult(ctx, res, err)
}
func (hand *Handler) GetIndex(ctx *router.Context) {
filename := "index.html"
filename = filepath.Join(hand.sharedir, filename)
file, err := os.Open(filename)
if err != nil {
hand.log.Errorf("cannot open file %s: %v", filename, err)
return
}
stat, _ := file.Stat()
ctx.Writer.Header().Set("Content-Type", "text/html; charset=utf-8")
ctx.Writer.Header().Set("Content-Length", fmt.Sprintf("%d", stat.Size()))
defer file.Close()
io.Copy(ctx.Writer, file)
//ctx.Writer.Write([]byte(payload))
}
/*
func (hand *Handler) SendHTML(ctx *router.Context, filename string) {
ctx.Writer.Header().Set("Content-Type", "text/html; charset=utf-8")
file, _ := os.Open(filepath.Join(hand.sharedir, filename))
defer file.Close()
io.Copy(ctx.Writer, file)
//ctx.Writer.Write([]byte(payload))
}
*/

View File

@@ -13,18 +13,15 @@ type Response struct {
}
func (hand *Handler) SendResult(ctx *router.Context, res any, err error) {
var resp *Response
resp := &Response{
Result: res,
}
if err != nil {
resp = &Response{
Error: true,
Message: fmt.Sprintf("%v", err),
Result: res,
}
} else {
resp = &Response{
Error: false,
Result: res,
}
resp.Message = fmt.Sprintf("%v", err)
resp.Error = true
}
ctx.SendJSON(resp)
}

View File

@@ -77,6 +77,7 @@ func (srv *Server) Build() error {
// Create X509 certs
handlerConfig := &handler.HandlerConfig{
Datadir: srv.conf.DataPath,
Sharedir: srv.conf.SharePath,
Database: srv.db,
}
srv.hand, err = handler.NewHandler(handlerConfig)

View File

@@ -56,7 +56,8 @@ func (svc *Service) Build() error {
svc.rout.Use(router.NewLoggingMiddleware(svc.log.Infof))
svc.rout.Use(router.NewCorsMiddleware())
svc.rout.Get(`/api/v1/service/hello`, svc.hand.Hello)
svc.rout.Get(`/api/v1/service/hello`, svc.hand.GetHello)
svc.rout.Get(`/`, svc.hand.GetIndex)
svc.rout.NotFound(svc.hand.NotFound)

32
work/model/descr.go Normal file
View File

@@ -0,0 +1,32 @@
package main
type Link struct {
CallingSID string `json:"callingSId" yaml:"callingSId"`
RespondingSID string `json:"respondingSId" yaml:"respondingSId"`
LinkDate string `json:"linkDate" yaml:"linkDate"`
LinkMode string `json:"linkMode" yaml:"linkMode"`
LinkBand string `json:"linkBand" yaml:"linkBand"`
Frequence int64 `json:"band,omitempty" yaml:"band,omitempty"`
// Calling station signal evaluation from responding station
CSReadability int64 `json:"csReadability" yaml:"csReadability"`
CSStrength int64 `json:"csStrength" yaml:"csStrength"`
CSTone int64 `json:"csTone,omitempty" yaml:"csTone,omitempty"`
// Responding station signal evaluation from calling station
RSReadability int64 `json:"rsReadability" yaml:"rsReadability"`
RSStrength int64 `json:"rsStrength" yaml:"rsStrength"`
RSTone int64 `json:"rsTone,omitempty" yaml:"rsTone,omitempty"`
}
type Station struct {
StationID string `json:"stationId" yaml:"stationId"`
UTCOffset int64 `json:"utcOffset" yaml:"utcOffset"`
OperatorNames []string `json:"operatorNames" yaml:"operatorNames"`
Password string `json:"password" yaml:"password"`
}
func main() {
}