feature/fanout #3
			
				
			
		
		
		
	|  | @ -22,7 +22,7 @@ RedisCluster: | |||
|   Type: cluster | ||||
| 
 | ||||
| Neo4J: | ||||
|   URI: neo4j://localhost:7687 | ||||
|   URI: bolt://localhost:7687 | ||||
|   Username: neo4j | ||||
|   Password: yyyytttt | ||||
|   MaxConnectionPoolSize: 20 | ||||
|  |  | |||
|  | @ -19,6 +19,12 @@ func NewNeo4J(conf *Config, opts ...Option) *Client { | |||
| 
 | ||||
| 	neo4ji := &Client{ | ||||
| 		neo4jConf: driverConfig, | ||||
| 		serviceConf: Config{ | ||||
| 			URI:      conf.URI, | ||||
| 			Username: conf.Username, | ||||
| 			Password: conf.Password, | ||||
| 			LogLevel: conf.LogLevel, | ||||
| 		}, | ||||
| 	} | ||||
| 
 | ||||
| 	for _, opt := range opts { | ||||
|  | @ -35,13 +41,6 @@ func (c *Client) Conn() (neo4j.DriverWithContext, error) { | |||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("neo4j driver initialization error: %w", err) | ||||
| 	} | ||||
| 	defer func(driver neo4j.DriverWithContext, ctx context.Context) { | ||||
| 		err := driver.Close(ctx) | ||||
| 		if err != nil { | ||||
| 			// fmt
 | ||||
| 
 | ||||
| 		} | ||||
| 	}(driver, context.Background()) | ||||
| 
 | ||||
| 	ctx := context.Background() | ||||
| 	// Verify the connection to Neo4j.
 | ||||
|  |  | |||
|  | @ -28,6 +28,7 @@ func (l *AddUserToNetworkLogic) AddUserToNetwork(in *tweeting.AddUserToNetworkRe | |||
| 	// todo: add your logic here and delete this line
 | ||||
| 	err := l.svcCtx.SocialNetworkRepository.CreateUserNode(l.ctx, in.GetUid()) | ||||
| 	if err != nil { | ||||
| 		fmt.Println("gg88g88g8", err) | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	fmt.Println(err) | ||||
|  |  | |||
|  | @ -5,10 +5,7 @@ import ( | |||
| 	"app-cloudep-tweeting-service/internal/domain/repository" | ||||
| 	client4J "app-cloudep-tweeting-service/internal/lib/neo4j" | ||||
| 	"context" | ||||
| 	"fmt" | ||||
| 
 | ||||
| 	ers "code.30cm.net/digimon/library-go/errs" | ||||
| 	n4 "github.com/neo4j/neo4j-go-driver/v5/neo4j" | ||||
| 	"github.com/neo4j/neo4j-go-driver/v5/neo4j" | ||||
| ) | ||||
| 
 | ||||
| type SocialNetworkParam struct { | ||||
|  | @ -29,25 +26,28 @@ func MustSocialNetworkRepository(param SocialNetworkParam) repository.SocialNetw | |||
| } | ||||
| 
 | ||||
| func (s SocialNetworkRepository) CreateUserNode(ctx context.Context, uid string) error { | ||||
| 	// 執行 Cypher
 | ||||
| 	conn, err := s.neo4jClient.Conn() | ||||
| 	session, err := s.neo4jClient.Conn() | ||||
| 	if err != nil { | ||||
| 		return ers.DBError("failed to connect to node4j", err.Error()) | ||||
| 		return err | ||||
| 	} | ||||
| 	defer session.Close(ctx) | ||||
| 
 | ||||
| 	insert := map[string]any{ | ||||
| 	params := map[string]interface{}{ | ||||
| 		"uid": uid, | ||||
| 	} | ||||
| 
 | ||||
| 	result, err := conn.NewSession(ctx, n4.SessionConfig{ | ||||
| 		AccessMode: n4.AccessModeWrite, | ||||
| 	}).Run(ctx, "CREATE (n:Person {name: $name}) RETURN n", insert) | ||||
| 	_, err = session.NewSession(ctx, neo4j.SessionConfig{ | ||||
| 		AccessMode: neo4j.AccessModeWrite, | ||||
| 	}).Run(ctx, "CREATE (n:User {uid: $uid}) RETURN n", params) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 
 | ||||
| 	fmt.Println(result.Keys()) | ||||
| 	// // 處理結果
 | ||||
| 	// if run.Next(ctx) {
 | ||||
| 	// 	node := run.Record().AsMap()
 | ||||
| 	// 	fmt.Printf("Created Node: %v\n", node)
 | ||||
| 	// }
 | ||||
| 
 | ||||
| 	return nil | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -6,7 +6,6 @@ import ( | |||
| 	"app-cloudep-tweeting-service/internal/lib/neo4j" | ||||
| 	model "app-cloudep-tweeting-service/internal/model/mongo" | ||||
| 	"app-cloudep-tweeting-service/internal/repository" | ||||
| 
 | ||||
| 	"github.com/zeromicro/go-zero/core/stores/redis" | ||||
| 
 | ||||
| 	vi "code.30cm.net/digimon/library-go/validator" | ||||
|  |  | |||
|  | @ -6,7 +6,10 @@ import ( | |||
| 
 | ||||
| 	"app-cloudep-tweeting-service/gen_result/pb/tweeting" | ||||
| 	"app-cloudep-tweeting-service/internal/config" | ||||
| 	commentserviceServer "app-cloudep-tweeting-service/internal/server/commentservice" | ||||
| 	postserviceServer "app-cloudep-tweeting-service/internal/server/postservice" | ||||
| 	socialnetworkserviceServer "app-cloudep-tweeting-service/internal/server/socialnetworkservice" | ||||
| 	timelineserviceServer "app-cloudep-tweeting-service/internal/server/timelineservice" | ||||
| 	"app-cloudep-tweeting-service/internal/svc" | ||||
| 
 | ||||
| 	"github.com/zeromicro/go-zero/core/conf" | ||||
|  | @ -18,8 +21,6 @@ import ( | |||
| 
 | ||||
| var configFile = flag.String("f", "etc/tweeting.yaml", "the config file") | ||||
| 
 | ||||
| // TODO 要把每一個錯誤代碼修改的更詳細,目前都資料庫錯誤
 | ||||
| 
 | ||||
| func main() { | ||||
| 	flag.Parse() | ||||
| 
 | ||||
|  | @ -29,6 +30,9 @@ func main() { | |||
| 
 | ||||
| 	s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) { | ||||
| 		tweeting.RegisterPostServiceServer(grpcServer, postserviceServer.NewPostServiceServer(ctx)) | ||||
| 		tweeting.RegisterCommentServiceServer(grpcServer, commentserviceServer.NewCommentServiceServer(ctx)) | ||||
| 		tweeting.RegisterTimelineServiceServer(grpcServer, timelineserviceServer.NewTimelineServiceServer(ctx)) | ||||
| 		tweeting.RegisterSocialNetworkServiceServer(grpcServer, socialnetworkserviceServer.NewSocialNetworkServiceServer(ctx)) | ||||
| 
 | ||||
| 		if c.Mode == service.DevMode || c.Mode == service.TestMode { | ||||
| 			reflection.Register(grpcServer) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue