Skip to content

Go gRPC server for performing unary gRPC requests

License

Notifications You must be signed in to change notification settings

kunal768/go-grpc-tc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-grpc-tc

Go gRPC server for demonstrating unary gRPC requests

To Build

go build -o go-grpc-tc

To Run

go run main.go

Run Unit Tests

go test ./user    

For Accessing gRPC endpopints :

Use a gRPC client tool like POSTMAN and upload the proto file

Important

After uploading the proto file Set url to "localhost:8080" and select appropriate service from dropdown at the right
Example screenshots are attahced

Note

On starting the server two users are seeded by default into the databases, they are as follows :
1: {ID: 1, FName: "John", City: "New York", Phone: 1234567890, Height: 180.5, Married: true}
2: {ID: 2, FName: "Jane", City: "Los Angeles", Phone: 9876543210, Height: 165.2, Married: false}

User Model

type User struct {
    ID   UserId
    FName  string
    City  string
    Phone  int64
    Height float64
    Married bool
}

Request/Response examples for gRPC server

Get User By Id

Request
{
    "id": 1
}
Response
{
    "user": {
        "id": 1,
        "fname": "John",
        "city": "New York",
        "phone": "1234567890",
        "height": 180.5,
        "married": true
    }
}

Get User By Id (Invalid)

Request
{
    "id": 0
}
Response
{
  Invalid argument
  You have specified an invalid argument.
}

Get Users By Id

Request
{
    "ids": [2, 45]
}
Response
{
    "users": [
        {
            "id": 2,
            "fname": "Jane",
            "city": "Los Angeles",
            "phone": "9876543210",
            "height": 165.2,
            "married": false
        },
        {
            "id": 45,
            "fname": "reprehenderit consectetur exercitation velit Ut",
            "city": "Lorem aliqua",
            "phone": "8442039398",
            "height": 48909313.409837335,
            "married": false
        }
    ]
}

Search Users By Fname

Request
{
    "fname": "Jane"
}
Response
{
    "users": [
        {
            "id": 2,
            "fname": "Jane",
            "city": "Los Angeles",
            "phone": "9876543210",
            "height": 165.2,
            "married": false
        }
    ]
}

Search Users By City

Request
{
    "city": "New York"
}
Response
{
    "users": [
        {
            "id": 1,
            "fname": "John",
            "city": "New York",
            "phone": "1234567890",
            "height": 180.5,
            "married": true
        }
    ]
}

Search Users By Phone

Request
{
    "phone": "8442039398"
}
Response
{
    "users": [
        {
            "id": 45,
            "fname": "reprehenderit consectetur exercitation velit Ut",
            "city": "Lorem aliqua",
            "phone": "8442039398",
            "height": 48909313.409837335,
            "married": false
        }
    ]
}

Search Users By Married Status

Request
{
    "married": false,
    "searchmarried": true
}
Response
{
    "users": [
        {
            "id": 2,
            "fname": "Jane",
            "city": "Los Angeles",
            "phone": "9876543210",
            "height": 165.2,
            "married": false
        },
        {
            "id": 45,
            "fname": "reprehenderit consectetur exercitation velit Ut",
            "city": "Lorem aliqua",
            "phone": "8442039398",
            "height": 48909313.409837335,
            "married": false
        }
    ]
}

Add Users Valid

Request
{
    "city": "Lorem aliqua",
    "fname": "reprehenderit consectetur exercitation velit Ut",
    "height": 48909313.409837335,
    "id": 45,
    "married": false,
    "phone": "8442039398"
}
Response
{
    "user": {
        "id": 45,
        "fname": "reprehenderit consectetur exercitation velit Ut",
        "city": "Lorem aliqua",
        "phone": "8442039398",
        "height": 48909313.409837335,
        "married": false
    }
}

Add Users Invalid

Request
{
    
}
Response
{
  Invalid argument
  You have specified an invalid argument.
}

List Users

Note

By default page is set to 1 and and pageSize is 10 (i.e. if request body is empty )

Request
{
    "page": 1,
    "pageSize": 1
}
Response
{
    "users": [
        {
            "id": 2,
            "fname": "Jane",
            "city": "Los Angeles",
            "phone": "9876543210",
            "height": 165.2,
            "married": false
        }
    ]
}

Screenshots

Screenshot 2024-07-08 at 5 22 43 PM Screenshot 2024-07-08 at 5 22 53 PM Screenshot 2024-07-08 at 5 23 10 PM Screenshot 2024-07-08 at 5 23 23 PM Screenshot 2024-07-08 at 5 23 35 PM Screenshot 2024-07-08 at 5 23 56 PM Screenshot 2024-07-08 at 5 24 05 PM Screenshot 2024-07-08 at 5 24 12 PM Screenshot 2024-07-08 at 5 24 19 PM Screenshot 2024-07-08 at 5 24 27 PM

About

Go gRPC server for performing unary gRPC requests

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages