You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

string.go 2.7 kB

2 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Copyright 2023 The casbin Authors. All Rights Reserved.
  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 util
  15. import (
  16. "errors"
  17. "fmt"
  18. "io/ioutil"
  19. "strconv"
  20. "strings"
  21. )
  22. func IndexAt(s, sep string, n int) int {
  23. idx := strings.Index(s[n:], sep)
  24. if idx > -1 {
  25. idx += n
  26. }
  27. return idx
  28. }
  29. func ParseInt(s string) int {
  30. i, err := strconv.Atoi(s)
  31. if err != nil {
  32. panic(err)
  33. }
  34. return i
  35. }
  36. func ParseIntWithError(s string) (int, error) {
  37. i, err := strconv.Atoi(s)
  38. if err != nil {
  39. return -1, err
  40. }
  41. if i < 0 {
  42. return -1, errors.New("negative version number")
  43. }
  44. return i, nil
  45. }
  46. func ParseFloat(s string) float64 {
  47. f, err := strconv.ParseFloat(s, 64)
  48. if err != nil {
  49. panic(err)
  50. }
  51. return f
  52. }
  53. func GetOwnerAndNameFromId(id string) (string, string) {
  54. tokens := strings.Split(id, "/")
  55. if len(tokens) != 2 {
  56. panic(errors.New("GetOwnerAndNameFromId() error, wrong token count for ID: " + id))
  57. }
  58. return tokens[0], tokens[1]
  59. }
  60. func GetOwnerAndNameFromId3(id string) (string, string, string) {
  61. tokens := strings.Split(id, "/")
  62. if len(tokens) != 3 {
  63. panic(errors.New("GetOwnerAndNameFromId3() error, wrong token count for ID: " + id))
  64. }
  65. return tokens[0], fmt.Sprintf("%s/%s", tokens[0], tokens[1]), tokens[2]
  66. }
  67. func GetOwnerAndNameFromId3New(id string) (string, string, string) {
  68. tokens := strings.Split(id, "/")
  69. if len(tokens) != 3 {
  70. panic(errors.New("GetOwnerAndNameFromId3New() error, wrong token count for ID: " + id))
  71. }
  72. return tokens[0], tokens[1], tokens[2]
  73. }
  74. func GetIdFromOwnerAndName(owner string, name string) string {
  75. return fmt.Sprintf("%s/%s", owner, name)
  76. }
  77. func ReadStringFromPath(path string) string {
  78. data, err := ioutil.ReadFile(path)
  79. if err != nil {
  80. panic(err)
  81. }
  82. return string(data)
  83. }
  84. func WriteStringToPath(s string, path string) {
  85. err := ioutil.WriteFile(path, []byte(s), 0644)
  86. if err != nil {
  87. panic(err)
  88. }
  89. }
  90. func ReadBytesFromPath(path string) []byte {
  91. data, err := ioutil.ReadFile(path)
  92. if err != nil {
  93. panic(err)
  94. }
  95. return data
  96. }
  97. func WriteBytesToPath(b []byte, path string) {
  98. err := ioutil.WriteFile(path, b, 0644)
  99. if err != nil {
  100. panic(err)
  101. }
  102. }

Caswire是一款基于人工智能技术的开源反病毒和入侵检测系统。该系统通过深度学习和模式识别技术,能够实时识别和防御各种网络威胁,包括病毒、恶意软件以及其他安全威胁。Caswire支持动态学习和适应网络环境的变化,确保持续的安全防护。我们期望在Caswire上:1)增强其机器学习模型,以提高恶意行为的检测准确率;2)优化系统的实时响应能力,提升在高威胁环境下的表现。