mirror of
				https://github.com/samber/lo.git
				synced 2025-10-31 19:43:08 +08:00 
			
		
		
		
	style: replace interface{} by any
This commit is contained in:
		
							
								
								
									
										20
									
								
								errors.go
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								errors.go
									
									
									
									
									
								
							| @@ -15,7 +15,7 @@ func Validate(ok bool, format string, args ...any) error { | |||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func messageFromMsgAndArgs(msgAndArgs ...interface{}) string { | func messageFromMsgAndArgs(msgAndArgs ...any) string { | ||||||
| 	if len(msgAndArgs) == 1 { | 	if len(msgAndArgs) == 1 { | ||||||
| 		if msgAsStr, ok := msgAndArgs[0].(string); ok { | 		if msgAsStr, ok := msgAndArgs[0].(string); ok { | ||||||
| 			return msgAsStr | 			return msgAsStr | ||||||
| @@ -29,7 +29,7 @@ func messageFromMsgAndArgs(msgAndArgs ...interface{}) string { | |||||||
| } | } | ||||||
|  |  | ||||||
| // must panics if err is error or false. | // must panics if err is error or false. | ||||||
| func must(err any, messageArgs ...interface{}) { | func must(err any, messageArgs ...any) { | ||||||
| 	if err == nil { | 	if err == nil { | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| @@ -61,54 +61,54 @@ func must(err any, messageArgs ...interface{}) { | |||||||
| // Must is a helper that wraps a call to a function returning a value and an error | // Must is a helper that wraps a call to a function returning a value and an error | ||||||
| // and panics if err is error or false. | // and panics if err is error or false. | ||||||
| // Play: https://go.dev/play/p/TMoWrRp3DyC | // Play: https://go.dev/play/p/TMoWrRp3DyC | ||||||
| func Must[T any](val T, err any, messageArgs ...interface{}) T { | func Must[T any](val T, err any, messageArgs ...any) T { | ||||||
| 	must(err, messageArgs...) | 	must(err, messageArgs...) | ||||||
| 	return val | 	return val | ||||||
| } | } | ||||||
|  |  | ||||||
| // Must0 has the same behavior as Must, but callback returns no variable. | // Must0 has the same behavior as Must, but callback returns no variable. | ||||||
| // Play: https://go.dev/play/p/TMoWrRp3DyC | // Play: https://go.dev/play/p/TMoWrRp3DyC | ||||||
| func Must0(err any, messageArgs ...interface{}) { | func Must0(err any, messageArgs ...any) { | ||||||
| 	must(err, messageArgs...) | 	must(err, messageArgs...) | ||||||
| } | } | ||||||
|  |  | ||||||
| // Must1 is an alias to Must | // Must1 is an alias to Must | ||||||
| // Play: https://go.dev/play/p/TMoWrRp3DyC | // Play: https://go.dev/play/p/TMoWrRp3DyC | ||||||
| func Must1[T any](val T, err any, messageArgs ...interface{}) T { | func Must1[T any](val T, err any, messageArgs ...any) T { | ||||||
| 	return Must(val, err, messageArgs...) | 	return Must(val, err, messageArgs...) | ||||||
| } | } | ||||||
|  |  | ||||||
| // Must2 has the same behavior as Must, but callback returns 2 variables. | // Must2 has the same behavior as Must, but callback returns 2 variables. | ||||||
| // Play: https://go.dev/play/p/TMoWrRp3DyC | // Play: https://go.dev/play/p/TMoWrRp3DyC | ||||||
| func Must2[T1, T2 any](val1 T1, val2 T2, err any, messageArgs ...interface{}) (T1, T2) { | func Must2[T1, T2 any](val1 T1, val2 T2, err any, messageArgs ...any) (T1, T2) { | ||||||
| 	must(err, messageArgs...) | 	must(err, messageArgs...) | ||||||
| 	return val1, val2 | 	return val1, val2 | ||||||
| } | } | ||||||
|  |  | ||||||
| // Must3 has the same behavior as Must, but callback returns 3 variables. | // Must3 has the same behavior as Must, but callback returns 3 variables. | ||||||
| // Play: https://go.dev/play/p/TMoWrRp3DyC | // Play: https://go.dev/play/p/TMoWrRp3DyC | ||||||
| func Must3[T1, T2, T3 any](val1 T1, val2 T2, val3 T3, err any, messageArgs ...interface{}) (T1, T2, T3) { | func Must3[T1, T2, T3 any](val1 T1, val2 T2, val3 T3, err any, messageArgs ...any) (T1, T2, T3) { | ||||||
| 	must(err, messageArgs...) | 	must(err, messageArgs...) | ||||||
| 	return val1, val2, val3 | 	return val1, val2, val3 | ||||||
| } | } | ||||||
|  |  | ||||||
| // Must4 has the same behavior as Must, but callback returns 4 variables. | // Must4 has the same behavior as Must, but callback returns 4 variables. | ||||||
| // Play: https://go.dev/play/p/TMoWrRp3DyC | // Play: https://go.dev/play/p/TMoWrRp3DyC | ||||||
| func Must4[T1, T2, T3, T4 any](val1 T1, val2 T2, val3 T3, val4 T4, err any, messageArgs ...interface{}) (T1, T2, T3, T4) { | func Must4[T1, T2, T3, T4 any](val1 T1, val2 T2, val3 T3, val4 T4, err any, messageArgs ...any) (T1, T2, T3, T4) { | ||||||
| 	must(err, messageArgs...) | 	must(err, messageArgs...) | ||||||
| 	return val1, val2, val3, val4 | 	return val1, val2, val3, val4 | ||||||
| } | } | ||||||
|  |  | ||||||
| // Must5 has the same behavior as Must, but callback returns 5 variables. | // Must5 has the same behavior as Must, but callback returns 5 variables. | ||||||
| // Play: https://go.dev/play/p/TMoWrRp3DyC | // Play: https://go.dev/play/p/TMoWrRp3DyC | ||||||
| func Must5[T1, T2, T3, T4, T5 any](val1 T1, val2 T2, val3 T3, val4 T4, val5 T5, err any, messageArgs ...interface{}) (T1, T2, T3, T4, T5) { | func Must5[T1, T2, T3, T4, T5 any](val1 T1, val2 T2, val3 T3, val4 T4, val5 T5, err any, messageArgs ...any) (T1, T2, T3, T4, T5) { | ||||||
| 	must(err, messageArgs...) | 	must(err, messageArgs...) | ||||||
| 	return val1, val2, val3, val4, val5 | 	return val1, val2, val3, val4, val5 | ||||||
| } | } | ||||||
|  |  | ||||||
| // Must6 has the same behavior as Must, but callback returns 6 variables. | // Must6 has the same behavior as Must, but callback returns 6 variables. | ||||||
| // Play: https://go.dev/play/p/TMoWrRp3DyC | // Play: https://go.dev/play/p/TMoWrRp3DyC | ||||||
| func Must6[T1, T2, T3, T4, T5, T6 any](val1 T1, val2 T2, val3 T3, val4 T4, val5 T5, val6 T6, err any, messageArgs ...interface{}) (T1, T2, T3, T4, T5, T6) { | func Must6[T1, T2, T3, T4, T5, T6 any](val1 T1, val2 T2, val3 T3, val4 T4, val5 T5, val6 T6, err any, messageArgs ...any) (T1, T2, T3, T4, T5, T6) { | ||||||
| 	must(err, messageArgs...) | 	must(err, messageArgs...) | ||||||
| 	return val1, val2, val3, val4, val5, val6 | 	return val1, val2, val3, val4, val5, val6 | ||||||
| } | } | ||||||
|   | |||||||
| @@ -25,7 +25,7 @@ func TestIsNil(t *testing.T) { | |||||||
| 	var b *bool | 	var b *bool | ||||||
| 	is.True(IsNil(b)) | 	is.True(IsNil(b)) | ||||||
|  |  | ||||||
| 	var ifaceWithNilValue interface{} = (*string)(nil) | 	var ifaceWithNilValue any = (*string)(nil) | ||||||
| 	is.True(IsNil(ifaceWithNilValue)) | 	is.True(IsNil(ifaceWithNilValue)) | ||||||
| 	is.False(ifaceWithNilValue == nil) // nolint:staticcheck | 	is.False(ifaceWithNilValue == nil) // nolint:staticcheck | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Samuel Berthe
					Samuel Berthe