Merge pull request 'Overhaul .proto files' (#1) from dev into main

Reviewed-on: https://codeberg.org/andcscott/OpenWeatherMap-gRPC-API/pulls/1
This commit is contained in:
Andrew Scott 2022-07-28 07:36:38 +02:00
commit 2490ef3a7c
8 changed files with 89 additions and 82 deletions

View file

@ -1,21 +0,0 @@
syntax = "proto3";
package weather;
option go_package = "codeberg.org/andcscott/OpenWeatherMap-gRPC-API/proto";
//import "location_types.proto";
//import "units.proto"
message RequestCurrent {
//LocationType location_type = 1; NOT IMPLEMENTED YET
//Units units = 2; NOT IMPLEMENTED YET
string city = 1;
// optional string zip_code = 2; NOT IMPLEMENTED YET
// optional string state = 2; // US Only / NOT IMPLEMENTED YET
// optional string country = 3; // Must be an ISO 3166 code / NOT IMPLEMENTED YET
}
message SendCurrent {
string payload = 1;
}

View file

@ -1,22 +0,0 @@
syntax = "proto3";
package weather;
option go_package = "codeberg.org/andcscott/OpenWeatherMap-gRPC-API/proto";
//import "location_types.proto";
//import "units.proto"
message RequestExtended {
//LocationType location_type = 1; NOT IMPLEMENTED YET
//Units units = 2; NOT IMPLEMENTED YET
string city = 1;
// optional string zip_code = 2; NOT IMPLEMENTED YET
// optional string state = 2; // US Only / NOT IMPLEMENTED YET
// optional string country = 3; // Must be ISO 3166 code / NOT IMPLEMENTED YET
uint32 days = 2;
}
message SendExtended {
string payload = 1;
}

View file

@ -4,18 +4,37 @@ package weather;
option go_package = "codeberg.org/andcscott/OpenWeatherMap-gRPC-API/proto";
//import "location_types.proto";
//import "units.proto"
message RequestLocation {
//LocationType location_type = 1; NOT IMPLEMENTED YET
//Units units = 2; NOT IMPLEMENTED YET
string city = 1;
// optional string zip_code = 2; NOT IMPLEMENTED YET
// optional string state = 2; // US Only / NOT IMPLEMENTED YET
// optional string country = 3; // Must be an ISO 3166 code / NOT IMPLEMENTED YET
// Sub-message used by Current & Extended for exact coordinates
message Coordinates {
float latitude = 1;
float longitude = 2;
}
// Used by Location, Current, and Extended to help the API find info for the
// correct location. If unspecified, an attept is still made but results may
// be inaccurate
enum LocationType {
LOCATION_TYPE_UNSPECIFIED = 0;
LOCATION_CITY = 1;
LOCATION_ZIP = 2;
LOCATION_COORDS = 3;
}
/* Get the latitude and longitude for a given location
* Commented parameters in the message definition are not implemeneted yet
* location_type {enum} - name or value
* city {string} - case insensitive, spaces and punctuation allowed
* zip_code {string} - non-numeric values permitted
*/
message RequestLocation {
// LocationType location_type = 1;
string city = 1;
// optional string zip_code = 2;
}
// Response to RequestLocation
message SendLocation {
float latitude = 1;
float longitude = 2;

View file

@ -1,15 +0,0 @@
syntax = "proto3";
package weather;
option go_package = "codeberg.org/andcscott/OpenWeatherMap-gRPC-API/proto";
enum LocationType {
LOCATION_TYPE_UNSPECIFIED = 0;
LOCATION_CITY = 1;
LOCATION_ZIP = 2;
LOCATION_COORDS = 3;
LOCATION_CITY_STATE = 4;
LOCATION_CITY_COUNTRY = 5;
LOCATION_ZIP_COUNTRY = 6;
}

View file

@ -4,8 +4,7 @@ package weather;
option go_package = "codeberg.org/andcscott/OpenWeatherMap-gRPC-API/proto";
import "current.proto";
import "extended.proto";
import "weather.proto";
import "location.proto";
service WeatherService {

View file

@ -1,12 +0,0 @@
syntax = "proto3";
package weather;
option go_package = "codeberg.org/andcscott/OpenWeatherMap-gRPC-API/proto";
enum Units {
UNITS_UNSPECIFIED = 0;
UNITS_STANDARD = 1;
UNITS_METRIC = 2;
UNITS_IMPERIAL = 3;
}

59
proto/weather.proto Normal file
View file

@ -0,0 +1,59 @@
syntax = "proto3";
package weather;
option go_package = "codeberg.org/andcscott/OpenWeatherMap-gRPC-API/proto";
//import "location.proto"
// Sub-message used by Current & Extended to specify preferred units
enum Units {
UNITS_UNSPECIFIED = 0;
UNITS_STANDARD = 1;
UNITS_METRIC = 2;
UNITS_IMPERIAL = 3;
}
/* Get the current forecast for a given location
* Commented parameters in the message definition are not implemeneted yet
* location_type {enum} - name or value
* units {enum} - name or value
* city {string} - case insensitive, spaces and punctuation allowed
* zip_code {string} - non-numeric values permitted
* coordinates {Coordinates} - Coordinates message with latitude and longitude
*/
message RequestCurrent {
// LocationType location_type = 1;
// Units units = 2;
string city = 1;
// optional string zip_code = 2;
// Coordinates coordinates = 2;
}
// Response to RequestCurrent
message SendCurrent {
string payload = 1;
}
/* Get the extended forecast for a given location up to 16 days in the future
* Commented parameters in the message definition are not implemeneted yet
* location_type {enum} - name or value
* units {enum} - name or value
* city {string} - case insensitive, spaces and punctuation allowed
* zip_code {string} - non-numeric values permitted
* coordinates {Coordinates} - Coordinates message with latitude and longitude
* days {uint32} - number of days to fetch, max 16
*/
message RequestExtended {
// LocationType location_type = 1;
// Units units = 2;
string city = 1;
// optional string zip_code = 2;
// Coordinates coordinates = 3;
uint32 days = 2;
}
// Response to RequestExtended
message SendExtended {
string payload = 1;
}

View file

@ -29,8 +29,8 @@ func (s *Server) Location(ctx context.Context, in *pb.RequestLocation) (*pb.Send
}
// Used internally to fetch precise locations
// Receives gRPC requests (interface) and the location (string)
// Returns the latitude (float32) and longitude (float32) for a given location
// Receives the city name and the server's API key
// Returns the latitude and longitude for the given location
func getLocation(city string, key string) (float32, float32) {
url := "http://api.openweathermap.org/geo/1.0/direct?q="