diff options
author | Runxi Yu <me@runxiyu.org> | 2025-08-17 03:09:52 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-08-17 03:09:52 +0800 |
commit | 009a6e397651a9540b6c6bb74ef2230eeda9b577 (patch) | |
tree | 0a808670d95aba5804a73a558cc335a49d230aa6 /forged/internal/ipc/git2c/client.go | |
parent | Remove HTML templates from main server (diff) | |
download | forge-009a6e397651a9540b6c6bb74ef2230eeda9b577.tar.gz forge-009a6e397651a9540b6c6bb74ef2230eeda9b577.tar.zst forge-009a6e397651a9540b6c6bb74ef2230eeda9b577.zip |
Some mass renaming
Diffstat (limited to 'forged/internal/ipc/git2c/client.go')
-rw-r--r-- | forged/internal/ipc/git2c/client.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/forged/internal/ipc/git2c/client.go b/forged/internal/ipc/git2c/client.go new file mode 100644 index 0000000..d8dc2ea --- /dev/null +++ b/forged/internal/ipc/git2c/client.go @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: AGPL-3.0-only +// SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org> + +package git2c + +import ( + "fmt" + "net" + + "go.lindenii.runxiyu.org/forge/forged/internal/bare" +) + +// Client represents a connection to the git2d backend daemon. +type Client struct { + socketPath string + conn net.Conn + writer *bare.Writer + reader *bare.Reader +} + +// NewClient establishes a connection to a git2d socket and returns a new Client. +func NewClient(socketPath string) (*Client, error) { + conn, err := net.Dial("unix", socketPath) + if err != nil { + return nil, fmt.Errorf("git2d connection failed: %w", err) + } + + writer := bare.NewWriter(conn) + reader := bare.NewReader(conn) + + return &Client{ + socketPath: socketPath, + conn: conn, + writer: writer, + reader: reader, + }, nil +} + +// Close terminates the underlying socket connection. +func (c *Client) Close() error { + if c.conn != nil { + return c.conn.Close() + } + return nil +} |