Browse Source

patient_type
body_part

shao 1 week ago
parent
commit
bc75299535
9 changed files with 40 additions and 30 deletions
  1. 1 1
      cmd/server/server.go
  2. 3 1
      common/config.go
  3. 14 14
      common/enum.go
  4. 14 0
      common/utils.go
  5. 0 1
      go.mod
  6. 2 2
      models/initdata.go
  7. 1 1
      models/setup.go
  8. 1 1
      rpc_idl
  9. 4 9
      service/config.go

+ 1 - 1
cmd/server/server.go

@@ -44,7 +44,7 @@ var (
 
 func init() {
 	StartCmd.Flags().StringVarP(&configFolder, "config", "c", "config/", "Start server with provided configuration folder")
-	StartCmd.Flags().StringVarP(&addr, "addr", "a", "localhost:6102", "Tcp server listening on")
+	StartCmd.Flags().StringVarP(&addr, "addr", "a", "", "Tcp server listening on")
 	StartCmd.Flags().StringVarP(&mode, "mode", "m", "debug", "server mode ; eg:debug,test,release")
 }
 

+ 3 - 1
common/config.go

@@ -187,7 +187,9 @@ func SetupConfig(path string, addr string, mode string) {
 	ServerConfig = InitServer(cfgServer)
 
 	BasicConfig.Mode = mode
-	ServerConfig.Resource = addr
+	if addr != "" {
+		ServerConfig.Resource = addr
+	}
 
 	cfgLog := viper.Sub("logger")
 	if cfgLog == nil {

+ 14 - 14
common/enum.go

@@ -34,22 +34,22 @@ func AllLanguages() []Lang {
 type Source string
 
 const (
-	SOURCE_GUI     Source = "gui"
-	SOURCE_BROWSER Source = "browser"
-	SOURCE_ANDROID Source = "android"
-	SOURCE_DEV     Source = "dev"
+	SOURCE_ELECTRON Source = "ELectron"
+	SOURCE_BROWSER  Source = "Browser"
+	SOURCE_ANDROID  Source = "Android"
+	SOURCE_DEV      Source = "Dev"
 )
 
 func (p Source) ToString() string {
 	switch p {
-	case SOURCE_GUI:
-		return "gui"
+	case SOURCE_ELECTRON:
+		return "ELectron"
 	case SOURCE_BROWSER:
-		return "browser"
+		return "Browser"
 	case SOURCE_ANDROID:
-		return "android"
+		return "Android"
 	case SOURCE_DEV:
-		return "dev"
+		return "Dev"
 	default:
 		return ""
 	}
@@ -65,22 +65,22 @@ func ValidSources(sources []Source) bool {
 }
 
 func AllSources() []Source {
-	return []Source{SOURCE_GUI, SOURCE_BROWSER, SOURCE_ANDROID, SOURCE_DEV}
+	return []Source{SOURCE_ELECTRON, SOURCE_BROWSER, SOURCE_ANDROID, SOURCE_DEV}
 }
 
 type Product string
 
 const (
-	PRODUCT_DROC Product = "droc"
-	PRODUCT_VET  Product = "vetdroc"
+	PRODUCT_DROC Product = "DROC"
+	PRODUCT_VET  Product = "VETDROC"
 )
 
 func (p Product) ToString() string {
 	switch p {
 	case PRODUCT_DROC:
-		return "droc"
+		return "DROC"
 	case PRODUCT_VET:
-		return "vetdroc"
+		return "VETDROC"
 	default:
 		return ""
 	}

+ 14 - 0
common/utils.go

@@ -1,13 +1,19 @@
 package common
 
 import (
+	"context"
 	"crypto/aes"
 	"crypto/cipher"
 	"crypto/md5"
 	"encoding/hex"
+	"log/slog"
 	"time"
 )
 
+import (
+	md "google.golang.org/grpc/metadata"
+)
+
 var CstSh, _ = time.LoadLocation("Asia/Shanghai")
 
 const (
@@ -35,6 +41,14 @@ func MD5(v []byte) string {
 	return hex.EncodeToString(re)
 }
 
+func GetHeader(ctx context.Context) (Product, Source, Lang) {
+	m, ok := md.FromIncomingContext(ctx)
+	if ok {
+		slog.Debug("metadata.FromIncomingContext", "md", m)
+	}
+	return Product(m.Get("product")[0]), Source(m.Get("source")[0]), Lang(m.Get("language")[0])
+}
+
 var dbPwKey = []byte("X3O6wVF&6*&lSVk0*504V~q7>\"k]6S'*") // 32 bytes for AES-256
 var dbPwNonceHex = "1962a6f6f9999447632c8a34"
 

+ 0 - 1
go.mod

@@ -29,7 +29,6 @@ require (
 	github.com/sagikazarmark/locafero v0.9.0 // indirect
 	github.com/sourcegraph/conc v0.3.0 // indirect
 	github.com/spf13/afero v1.14.0 // indirect
-	github.com/spf13/cast v1.8.0 // indirect
 	github.com/spf13/pflag v1.0.6 // indirect
 	github.com/subosito/gotenv v1.6.0 // indirect
 	go.uber.org/multierr v1.11.0 // indirect

+ 2 - 2
models/initdata.go

@@ -16,8 +16,8 @@ import (
 	"resource-server/static"
 )
 
-func initConfigItem() error {
-	sqlFilePath := "config_items_202505221522.sql"
+func initTable(sqlFilePath string) error {
+	slog.Info("initTable ...", "file", sqlFilePath)
 	file, err := static.GetSqlFile(sqlFilePath)
 	if err != nil {
 		return fmt.Errorf("error opening SQL file: %w", err)

+ 1 - 1
models/setup.go

@@ -31,7 +31,7 @@ func migrate() {
 	var count int64
 	DB.Model(&ConfigItem{}).Count(&count)
 	if count == 0 {
-		panicHelper(initConfigItem())
+		panicHelper(initTable("config_items_202505221522.sql"))
 	}
 }
 

+ 1 - 1
rpc_idl

@@ -1 +1 @@
-Subproject commit 9dd27d243c67beca28b8dc0665ce060c6989e7e7
+Subproject commit fd1299aaac1e201fdd1a946f14143d93f04e4c14

+ 4 - 9
service/config.go

@@ -2,12 +2,11 @@ package service
 
 import (
 	"context"
-	"fmt"
+	"resource-server/common"
 )
 
 import (
 	"google.golang.org/grpc/codes"
-	"google.golang.org/grpc/metadata"
 	"google.golang.org/grpc/status"
 )
 
@@ -20,10 +19,7 @@ type ConfigServer struct {
 }
 
 func (s *ConfigServer) ConfigOptionList(ctx context.Context, in *pb.ConfigOptionListRequest) (*pb.ConfigOptionListReply, error) {
-	md, ok := metadata.FromIncomingContext(ctx)
-	if ok {
-		fmt.Printf("Received metadata: %v\n", md)
-	}
+	product, _, _ := common.GetHeader(ctx)
 	res := pb.ConfigOptionListReply{}
 	switch in.GetFlag() {
 	case "TimeFormat":
@@ -60,12 +56,11 @@ func (s *ConfigServer) ConfigOptionList(ctx context.Context, in *pb.ConfigOption
 		res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "FontFamily", Text: "Arial Unicode MS", Value: "Arial Unicode MS", Order: 1, IsEnabled: true})
 		res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "FontFamily", Text: "Arial", Value: "Arial", Order: 2, IsEnabled: true})
 	case "MWL_Modality":
-		if md.Get("product")[0] == "vetdroc" {
+		if product == common.PRODUCT_VET {
 			res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "MWL_Modality", Text: "RF", Value: "RF", Order: 1, IsEnabled: true})
 			res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "MWL_Modality", Text: "DX", Value: "DX", Order: 2, IsEnabled: true})
 			res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "MWL_Modality", Text: "XA", Value: "XA", Order: 3, IsEnabled: true})
-		}
-		if md.Get("product")[0] == "droc" {
+		} else if product == common.PRODUCT_DROC {
 			res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "MWL_Modality", Text: "DX", Value: "DX", Order: 1, IsEnabled: true})
 			res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "MWL_Modality", Text: "CR", Value: "CR", Order: 2, IsEnabled: true})
 		}