main.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2016 fatedier, [email protected]
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package frpclib
  15. import (
  16. "math/rand"
  17. "strings"
  18. "time"
  19. _ "github.com/fatedier/frp/assets/frpc"
  20. "github.com/fatedier/frp/cmd/frpc/sub"
  21. "github.com/fatedier/golib/crypto"
  22. )
  23. func main() {
  24. crypto.DefaultSalt = "frp"
  25. rand.Seed(time.Now().UnixNano())
  26. sub.Execute()
  27. }
  28. func RunFile(uid string, cfgFilePath string) (errString string) {
  29. crypto.DefaultSalt = "frp"
  30. err, _ := sub.RunClientWithUid(uid, cfgFilePath)
  31. if err != nil {
  32. return err.Error()
  33. }
  34. return ""
  35. }
  36. func RunContent(uid string, cfgContent string) (errString string) {
  37. crypto.DefaultSalt = "frp"
  38. err, _ := sub.RunClientByContent(uid, cfgContent)
  39. if err != nil {
  40. return err.Error()
  41. }
  42. return ""
  43. }
  44. func Close(uid string) (ret bool) {
  45. return sub.Close(uid)
  46. }
  47. func GetUids() string {
  48. uids := sub.GetUids()
  49. return strings.Join(uids, ",")
  50. }
  51. func IsRunning(uid string) (running bool) {
  52. return sub.IsRunning(uid)
  53. }