Add grpc impl
This commit is contained in:
34
logger-service/cmd/api/grpc.go
Normal file
34
logger-service/cmd/api/grpc.go
Normal file
@ -0,0 +1,34 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"logger/data"
|
||||
"logger/logs"
|
||||
)
|
||||
|
||||
type LogServer struct {
|
||||
logs.UnimplementedLogServiceServer
|
||||
Models data.Models
|
||||
}
|
||||
|
||||
func (l *LogServer) WriteLog(
|
||||
ctx context.Context,
|
||||
req *logs.LogRequest,
|
||||
) (*logs.LogResponse, error) {
|
||||
input := req.GetLogEntry()
|
||||
|
||||
// write the log
|
||||
logEntry := data.LogEntry{
|
||||
Name: input.Name,
|
||||
Data: input.Data,
|
||||
}
|
||||
|
||||
err := l.Models.LogEntry.Insert(logEntry)
|
||||
if err != nil {
|
||||
res := &logs.LogResponse{Result: "failed"}
|
||||
return res, err
|
||||
}
|
||||
|
||||
res := &logs.LogResponse{Result: "logged!"}
|
||||
return res, nil
|
||||
}
|
Reference in New Issue
Block a user