wy-os commented on code in PR #2437: URL: https://github.com/apache/streampipes/pull/2437#discussion_r1494036831
########## streampipes-client-go/streampipes/streampipes_client.go: ########## @@ -0,0 +1,80 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package streampipes + +import ( + "errors" + "log" + "net/url" + "regexp" + "streampipes-client-go/streampipes/api" + "streampipes-client-go/streampipes/config" + "streampipes-client-go/streampipes/internal/credential" + "strings" +) + +/* + This is the central point of contact with StreamPipes and provides all the functionalities to interact with it. + The client provides so-called "API", each of which refers to the endpoint of the StreamPipes API. + e.g. `DataLakeMeasureApi` provides the actual methods to interact with StreamPipes API. +*/ + +type StreamPipesClient struct { + Config config.StreamPipesClientConnectionConfig +} + +func NewStreamPipesClient(config config.StreamPipesClientConnectionConfig) (*StreamPipesClient, error) { + + //NewStreamPipesClient returns an instance of * StreamPipesClient + //Temporarily does not support HTTPS connections, nor does it support connecting to port 443 + + if config.Credential == (credential.StreamPipesApiKeyCredentials{}) { + log.Fatal("No credential entered") + } + + re := regexp.MustCompile(`(?i)^(http|https):\/\/[^\s\/:]+:\d+$`) + ok := re.MatchString(config.Url) + if !ok { + log.Fatal("Please check if the URL is correct,Must be in the form of A://B:C," + + "where A is either HTTP or HTTPS, not case sensitive.B must be the host and C must be the port.") + } Review Comment: The URL standard library of the go language seems to have flaws. In this case(If the URL format does not match“ http://host:port “), it may not be possible to correctly resolve ports, hosts, etc. So I used regular expressions to forcibly match URLs that match the format. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
